diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/postmaster/postmaster.c | 50 | ||||
-rw-r--r-- | src/backend/utils/misc/guc.c | 8 |
2 files changed, 47 insertions, 11 deletions
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index b2fe420c3cf..d16d881e570 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -896,15 +896,31 @@ PostmasterMain(int argc, char *argv[]) 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. + * If this is a runtime-computed GUC, it hasn't yet been initialized, + * and the present value is not useful. However, this is a convenient + * place to print the value for most GUCs because it is safe to run + * postmaster startup to this point even if the server is already + * running. For the handful of runtime-computed GUCs that we cannot + * provide meaningful values for yet, we wait until later in + * postmaster startup to print the value. We won't be able to use -C + * on running servers for those GUCs, but using this option now would + * lead to incorrect results for them. */ - const char *config_val = GetConfigOption(output_config_variable, - false, false); + int flags = GetConfigOptionFlags(output_config_variable, true); - puts(config_val ? config_val : ""); - ExitPostmaster(0); + if ((flags & GUC_RUNTIME_COMPUTED) == 0) + { + /* + * "-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 */ @@ -1034,6 +1050,26 @@ PostmasterMain(int argc, char *argv[]) InitializeShmemGUCs(); /* + * If -C was specified with a runtime-computed GUC, we held off printing + * the value earlier, as the GUC was not yet initialized. We handle -C + * for most GUCs before we lock the data directory so that the option may + * be used on a running server. However, a handful of GUCs are runtime- + * computed and do not have meaningful values until after locking the data + * directory, and we cannot safely calculate their values earlier on a + * running server. At this point, such GUCs should be properly + * initialized, and we haven't yet set up shared memory, so this is a good + * time to handle the -C option for these special GUCs. + */ + 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. */ reset_shared(); diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 23236fa4c3d..a6e4fcc24ed 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -1983,7 +1983,7 @@ static struct config_bool ConfigureNamesBool[] = {"data_checksums", PGC_INTERNAL, PRESET_OPTIONS, gettext_noop("Shows whether data checksums are turned on for this cluster."), NULL, - GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE + GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_RUNTIME_COMPUTED }, &data_checksums, false, @@ -2342,7 +2342,7 @@ static struct config_int ConfigureNamesInt[] = {"shared_memory_size", PGC_INTERNAL, PRESET_OPTIONS, gettext_noop("Shows the size of the server's main shared memory area (rounded up to the nearest MB)."), NULL, - GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_UNIT_MB + GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_UNIT_MB | GUC_RUNTIME_COMPUTED }, &shared_memory_size_mb, 0, 0, INT_MAX, @@ -2407,7 +2407,7 @@ static struct config_int ConfigureNamesInt[] = "in the form accepted by the chmod and umask system " "calls. (To use the customary octal format the number " "must start with a 0 (zero).)"), - GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE + GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_RUNTIME_COMPUTED }, &data_directory_mode, 0700, 0000, 0777, @@ -3231,7 +3231,7 @@ static struct config_int ConfigureNamesInt[] = {"wal_segment_size", PGC_INTERNAL, PRESET_OPTIONS, gettext_noop("Shows the size of write ahead log segments."), NULL, - GUC_UNIT_BYTE | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE + GUC_UNIT_BYTE | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_RUNTIME_COMPUTED }, &wal_segment_size, DEFAULT_XLOG_SEG_SIZE, |