Commit 418039d3 authored by Heikki Linnakangas's avatar Heikki Linnakangas

Process options from the startup packed in walsender. Only few options

make sense for walsender, but for example application_name and client_encoding
do. We still don't apply per-role settings from pg_db_role_setting, because
that would require connecting to a database to read the table.

Fujii Masao
parent df57a5e8
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.213 2010/07/06 19:18:58 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.214 2010/09/13 09:00:30 heikki Exp $
* *
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
...@@ -65,6 +65,7 @@ static void CheckMyDatabase(const char *name, bool am_superuser); ...@@ -65,6 +65,7 @@ static void CheckMyDatabase(const char *name, bool am_superuser);
static void InitCommunication(void); static void InitCommunication(void);
static void ShutdownPostgres(int code, Datum arg); static void ShutdownPostgres(int code, Datum arg);
static bool ThereIsAtLeastOneRole(void); static bool ThereIsAtLeastOneRole(void);
static void process_startup_options(Port *port, bool am_superuser);
static void process_settings(Oid databaseid, Oid roleid); static void process_settings(Oid databaseid, Oid roleid);
...@@ -476,7 +477,6 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, ...@@ -476,7 +477,6 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
{ {
bool bootstrap = IsBootstrapProcessingMode(); bool bootstrap = IsBootstrapProcessingMode();
bool am_superuser; bool am_superuser;
GucContext gucctx;
char *fullpath; char *fullpath;
char dbname[NAMEDATALEN]; char dbname[NAMEDATALEN];
...@@ -650,21 +650,37 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, ...@@ -650,21 +650,37 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
errmsg("remaining connection slots are reserved for non-replication superuser connections"))); errmsg("remaining connection slots are reserved for non-replication superuser connections")));
/* /*
* If walsender, we're done here --- we don't want to connect to any * If walsender, we don't want to connect to any particular database.
* particular database. * Just finish the backend startup by processing any options from the
* startup packet, and we're done.
*/ */
if (am_walsender) if (am_walsender)
{ {
Assert(!bootstrap); Assert(!bootstrap);
/* must have authenticated as a superuser */ /* must have authenticated as a superuser */
if (!am_superuser) if (!am_superuser)
ereport(FATAL, ereport(FATAL,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser to start walsender"))); errmsg("must be superuser to start walsender")));
/* process any options passed in the startup packet */
if (MyProcPort != NULL)
process_startup_options(MyProcPort, am_superuser);
/* Apply PostAuthDelay as soon as we've read all options */
if (PostAuthDelay > 0)
pg_usleep(PostAuthDelay * 1000000L);
/* initialize client encoding */
InitializeClientEncoding();
/* report this backend in the PgBackendStatus array */ /* report this backend in the PgBackendStatus array */
pgstat_bestart(); pgstat_bestart();
/* close the transaction we started above */ /* close the transaction we started above */
CommitTransactionCommand(); CommitTransactionCommand();
return; return;
} }
...@@ -811,33 +827,76 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, ...@@ -811,33 +827,76 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
CheckMyDatabase(dbname, am_superuser); CheckMyDatabase(dbname, am_superuser);
/* /*
* Now process any command-line switches that were included in the startup * Now process any command-line switches and any additional GUC variable
* packet, if we are in a regular backend. We couldn't do this before * settings passed in the startup packet. We couldn't do this before
* because we didn't know if client is a superuser. * because we didn't know if client is a superuser.
*/ */
if (MyProcPort != NULL)
process_startup_options(MyProcPort, am_superuser);
/* Process pg_db_role_setting options */
process_settings(MyDatabaseId, GetSessionUserId());
/* Apply PostAuthDelay as soon as we've read all options */
if (PostAuthDelay > 0)
pg_usleep(PostAuthDelay * 1000000L);
/*
* Initialize various default states that can't be set up until we've
* selected the active user and gotten the right GUC settings.
*/
/* set default namespace search path */
InitializeSearchPath();
/* initialize client encoding */
InitializeClientEncoding();
/* report this backend in the PgBackendStatus array */
if (!bootstrap)
pgstat_bestart();
/* close the transaction we started above */
if (!bootstrap)
CommitTransactionCommand();
}
/*
* Process any command-line switches and any additional GUC variable
* settings passed in the startup packet.
*/
static void
process_startup_options(Port *port, bool am_superuser)
{
GucContext gucctx;
ListCell *gucopts;
gucctx = am_superuser ? PGC_SUSET : PGC_BACKEND; gucctx = am_superuser ? PGC_SUSET : PGC_BACKEND;
if (MyProcPort != NULL && /*
MyProcPort->cmdline_options != NULL) * First process any command-line switches that were included in the
* startup packet, if we are in a regular backend.
*/
if (port->cmdline_options != NULL)
{ {
/* /*
* The maximum possible number of commandline arguments that could * The maximum possible number of commandline arguments that could
* come from MyProcPort->cmdline_options is (strlen + 1) / 2; see * come from port->cmdline_options is (strlen + 1) / 2; see
* pg_split_opts(). * pg_split_opts().
*/ */
char **av; char **av;
int maxac; int maxac;
int ac; int ac;
maxac = 2 + (strlen(MyProcPort->cmdline_options) + 1) / 2; maxac = 2 + (strlen(port->cmdline_options) + 1) / 2;
av = (char **) palloc(maxac * sizeof(char *)); av = (char **) palloc(maxac * sizeof(char *));
ac = 0; ac = 0;
av[ac++] = "postgres"; av[ac++] = "postgres";
/* Note this mangles MyProcPort->cmdline_options */ /* Note this mangles port->cmdline_options */
pg_split_opts(av, &ac, MyProcPort->cmdline_options); pg_split_opts(av, &ac, port->cmdline_options);
av[ac] = NULL; av[ac] = NULL;
...@@ -850,10 +909,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, ...@@ -850,10 +909,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
* Process any additional GUC variable settings passed in startup packet. * Process any additional GUC variable settings passed in startup packet.
* These are handled exactly like command-line variables. * These are handled exactly like command-line variables.
*/ */
if (MyProcPort != NULL) gucopts = list_head(port->guc_options);
{
ListCell *gucopts = list_head(MyProcPort->guc_options);
while (gucopts) while (gucopts)
{ {
char *name; char *name;
...@@ -867,33 +923,6 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, ...@@ -867,33 +923,6 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
SetConfigOption(name, value, gucctx, PGC_S_CLIENT); SetConfigOption(name, value, gucctx, PGC_S_CLIENT);
} }
}
/* Process pg_db_role_setting options */
process_settings(MyDatabaseId, GetSessionUserId());
/* Apply PostAuthDelay as soon as we've read all options */
if (PostAuthDelay > 0)
pg_usleep(PostAuthDelay * 1000000L);
/*
* Initialize various default states that can't be set up until we've
* selected the active user and gotten the right GUC settings.
*/
/* set default namespace search path */
InitializeSearchPath();
/* initialize client encoding */
InitializeClientEncoding();
/* report this backend in the PgBackendStatus array */
if (!bootstrap)
pgstat_bestart();
/* close the transaction we started above */
if (!bootstrap)
CommitTransactionCommand();
} }
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment