From ba43a45c5ace5573589735514284d2dd1a6aec42 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Fri, 3 Sep 2021 16:41:31 +0000 Subject: [PATCH v5 2/4] Move postmaster "-C" logic to after processing preload libraries. This change allows us to return correct values for runtime-computed GUCs such as data_checksums and for future GUCs related to the amount of shared memory required for the server. One notable behavior change is that "-C" will now run all preload libraries' _PG_init() functions without locking the data directory. If a library's _PG_init() function might do something that would break a running server, it will need to be adjusted to be safe. --- src/backend/postmaster/postmaster.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 9c2c98614a..0fa2f41ddc 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -893,20 +893,6 @@ PostmasterMain(int argc, char *argv[]) if (!SelectConfigFiles(userDoption, progname)) ExitPostmaster(2); - if (output_config_variable != NULL) - { - /* - * "-C guc" was specified, so print GUC's value and exit. No extra - * permission check is needed because the user is reading inside the - * data dir. - */ - const char *config_val = GetConfigOption(output_config_variable, - false, false); - - puts(config_val ? config_val : ""); - ExitPostmaster(0); - } - /* Verify that DataDir looks reasonable */ checkDataDir(); @@ -982,8 +968,12 @@ PostmasterMain(int argc, char *argv[]) * is responsible for removing both data directory and socket lockfiles; * so it must happen before opening sockets so that at exit, the socket * lockfiles go away after CloseServerPorts runs. + * + * We skip this step if we are just going to print a GUC's value and exit + * a few steps down. */ - CreateDataDirLockFile(true); + if (output_config_variable == NULL) + CreateDataDirLockFile(true); /* * Read the control file (for error checking and config info). @@ -1026,6 +1016,19 @@ PostmasterMain(int argc, char *argv[]) */ InitializeMaxBackends(); + /* + * If user requested that we print a GUC's value and exit (via "-C guc"), + * do that now since we've loaded all configurations. + */ + if (output_config_variable != NULL) + { + const char *config_val = GetConfigOption(output_config_variable, + false, false); + + puts(config_val ? config_val : ""); + ExitPostmaster(0); + } + /* * Set up shared memory and semaphores. */ -- 2.16.6