From 2c6ed729d951621e34214abd1c532539530479ea Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Sat, 28 Aug 2021 05:02:55 +0000 Subject: [PATCH 1/1] add shared_memory_size GUC --- src/backend/postmaster/postmaster.c | 25 +++++++++++++++++++++++-- src/backend/utils/misc/guc.c | 13 +++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 9c2c98614a..38e28b3f8f 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -893,7 +893,8 @@ PostmasterMain(int argc, char *argv[]) if (!SelectConfigFiles(userDoption, progname)) ExitPostmaster(2); - if (output_config_variable != NULL) + if (output_config_variable != NULL && + strcmp(output_config_variable, "shared_memory_size") != 0) { /* * "-C guc" was specified, so print GUC's value and exit. No extra @@ -983,7 +984,8 @@ PostmasterMain(int argc, char *argv[]) * so it must happen before opening sockets so that at exit, the socket * lockfiles go away after CloseServerPorts runs. */ - CreateDataDirLockFile(true); + if (output_config_variable == NULL) + CreateDataDirLockFile(true); /* * Read the control file (for error checking and config info). @@ -1026,6 +1028,25 @@ PostmasterMain(int argc, char *argv[]) */ InitializeMaxBackends(); + { + char buf[64]; + Size size; + + size = CalculateShmemSize(NULL); + size += (1024 * 1024) - 1; + size /= (1024 * 1024); + + sprintf(buf, "%lu MB", size); + SetConfigOption("shared_memory_size", buf, PGC_INTERNAL, PGC_S_OVERRIDE); + } + + if (output_config_variable != NULL) + { + const char *val = GetConfigOption(output_config_variable, false, false); + puts(val); + ExitPostmaster(0); + } + /* * Set up shared memory and semaphores. */ diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 467b0fd6fe..7c88dbeae9 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -620,6 +620,8 @@ char *pgstat_temp_directory; char *application_name; +int shmem_size_mb; + int tcp_keepalives_idle; int tcp_keepalives_interval; int tcp_keepalives_count; @@ -2337,6 +2339,17 @@ static struct config_int ConfigureNamesInt[] = NULL, NULL, NULL }, + { + {"shared_memory_size", PGC_INTERNAL, RESOURCES_MEM, + gettext_noop("Shows the amount of shared memory allocated by the server (rounded up to the nearest MB)."), + NULL, + GUC_UNIT_MB + }, + &shmem_size_mb, + 0, 0, INT_MAX, + NULL, NULL, NULL + }, + { {"temp_buffers", PGC_USERSET, RESOURCES_MEM, gettext_noop("Sets the maximum number of temporary buffers used by each session."), -- 2.16.6