startup_packet_options_and_walsender_v1.patch
application/octet-stream
Filename: startup_packet_options_and_walsender_v1.patch
Type: application/octet-stream
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: context
Series: patch v1
| File | + | − |
|---|---|---|
| src/backend/utils/init/postinit.c | 55 | 0 |
*** a/src/backend/utils/init/postinit.c
--- b/src/backend/utils/init/postinit.c
***************
*** 65,70 **** static void CheckMyDatabase(const char *name, bool am_superuser);
--- 65,71 ----
static void InitCommunication(void);
static void ShutdownPostgres(int code, Datum arg);
static bool ThereIsAtLeastOneRole(void);
+ static void process_startup_options(Port *port, bool am_superuser);
static void process_settings(Oid databaseid, Oid roleid);
***************
*** 476,482 **** InitPostgres(const char *in_dbname, Oid dboid, const char *username,
{
bool bootstrap = IsBootstrapProcessingMode();
bool am_superuser;
- GucContext gucctx;
char *fullpath;
char dbname[NAMEDATALEN];
--- 477,482 ----
***************
*** 661,666 **** InitPostgres(const char *in_dbname, Oid dboid, const char *username,
--- 661,668 ----
ereport(FATAL,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser to start walsender")));
+ /* process any options passed in the startup packet */
+ process_startup_options(MyProcPort, am_superuser);
/* report this backend in the PgBackendStatus array */
pgstat_bestart();
/* close the transaction we started above */
***************
*** 811,843 **** InitPostgres(const char *in_dbname, Oid dboid, const char *username,
CheckMyDatabase(dbname, am_superuser);
/*
! * Now process any command-line switches that were included in the startup
! * packet, if we are in a regular backend. We couldn't do this before
* because we didn't know if client is a superuser.
*/
gucctx = am_superuser ? PGC_SUSET : PGC_BACKEND;
! if (MyProcPort != NULL &&
! MyProcPort->cmdline_options != NULL)
{
/*
* The maximum possible number of commandline arguments that could
! * come from MyProcPort->cmdline_options is (strlen + 1) / 2; see
* pg_split_opts().
*/
char **av;
int maxac;
int ac;
! maxac = 2 + (strlen(MyProcPort->cmdline_options) + 1) / 2;
av = (char **) palloc(maxac * sizeof(char *));
ac = 0;
av[ac++] = "postgres";
! /* Note this mangles MyProcPort->cmdline_options */
! pg_split_opts(av, &ac, MyProcPort->cmdline_options);
av[ac] = NULL;
--- 813,887 ----
CheckMyDatabase(dbname, am_superuser);
/*
! * Now process any command-line switches and any additional GUC variable
! * settings passed in the startup packet. We couldn't do this before
* because we didn't know if client is a superuser.
*/
+ 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;
+
+ /*
+ * Now process any command-line switches that were included in the startup
+ * packet, if we are in a regular backend.
+ */
gucctx = am_superuser ? PGC_SUSET : PGC_BACKEND;
! if (port != NULL &&
! port->cmdline_options != NULL)
{
/*
* The maximum possible number of commandline arguments that could
! * come from port->cmdline_options is (strlen + 1) / 2; see
* pg_split_opts().
*/
char **av;
int maxac;
int ac;
! maxac = 2 + (strlen(port->cmdline_options) + 1) / 2;
av = (char **) palloc(maxac * sizeof(char *));
ac = 0;
av[ac++] = "postgres";
! /* Note this mangles port->cmdline_options */
! pg_split_opts(av, &ac, port->cmdline_options);
av[ac] = NULL;
***************
*** 850,858 **** InitPostgres(const char *in_dbname, Oid dboid, const char *username,
* Process any additional GUC variable settings passed in startup packet.
* These are handled exactly like command-line variables.
*/
! if (MyProcPort != NULL)
{
! ListCell *gucopts = list_head(MyProcPort->guc_options);
while (gucopts)
{
--- 894,902 ----
* Process any additional GUC variable settings passed in startup packet.
* These are handled exactly like command-line variables.
*/
! if (port != NULL)
{
! ListCell *gucopts = list_head(port->guc_options);
while (gucopts)
{
***************
*** 868,899 **** InitPostgres(const char *in_dbname, Oid dboid, const char *username,
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();
}
/*
--- 912,917 ----