Skip to content

Commit bd17880

Browse files
committed
Introduce GUC shared_memory_size
This runtime-computed GUC shows the size of the server's main shared memory area, taking into account the amount of shared memory allocated by extensions as this is calculated after processing shared_preload_libraries. Author: Nathan Bossart Discussion: https://postgr.es/m/F2772387-CE0F-46BF-B5F1-CC55516EB885@amazon.com
1 parent fd0625c commit bd17880

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

doc/src/sgml/config.sgml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10275,6 +10275,20 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
1027510275
</listitem>
1027610276
</varlistentry>
1027710277

10278+
<varlistentry id="guc-shared-memory-size" xreflabel="shared_memory_size">
10279+
<term><varname>shared_memory_size</varname> (<type>integer</type>)
10280+
<indexterm>
10281+
<primary><varname>shared_memory_size</varname> configuration parameter</primary>
10282+
</indexterm>
10283+
</term>
10284+
<listitem>
10285+
<para>
10286+
Reports the size of the main shared memory area, rounded up to the
10287+
nearest megabyte.
10288+
</para>
10289+
</listitem>
10290+
</varlistentry>
10291+
1027810292
<varlistentry id="guc-ssl-library" xreflabel="ssl_library">
1027910293
<term><varname>ssl_library</varname> (<type>string</type>)
1028010294
<indexterm>

src/backend/postmaster/postmaster.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,13 @@ PostmasterMain(int argc, char *argv[])
10261026
*/
10271027
InitializeMaxBackends();
10281028

1029+
/*
1030+
* Now that loadable modules have had their chance to request additional
1031+
* shared memory, determine the value of any runtime-computed GUCs that
1032+
* depend on the amount of shared memory required.
1033+
*/
1034+
InitializeShmemGUCs();
1035+
10291036
/*
10301037
* Set up shared memory and semaphores.
10311038
*/

src/backend/storage/ipc/ipci.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,25 @@ CreateSharedMemoryAndSemaphores(void)
313313
if (shmem_startup_hook)
314314
shmem_startup_hook();
315315
}
316+
317+
/*
318+
* InitializeShmemGUCs
319+
*
320+
* This function initializes runtime-computed GUCs related to the amount of
321+
* shared memory required for the current configuration.
322+
*/
323+
void
324+
InitializeShmemGUCs(void)
325+
{
326+
char buf[64];
327+
Size size_b;
328+
Size size_mb;
329+
330+
/*
331+
* Calculate the shared memory size and round up to the nearest megabyte.
332+
*/
333+
size_b = CalculateShmemSize(NULL);
334+
size_mb = add_size(size_b, (1024 * 1024) - 1) / (1024 * 1024);
335+
sprintf(buf, "%lu", size_mb);
336+
SetConfigOption("shared_memory_size", buf, PGC_INTERNAL, PGC_S_OVERRIDE);
337+
}

src/backend/utils/misc/guc.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ static int max_index_keys;
664664
static int max_identifier_length;
665665
static int block_size;
666666
static int segment_size;
667+
static int shared_memory_size_mb;
667668
static int wal_block_size;
668669
static bool data_checksums;
669670
static bool integer_datetimes;
@@ -2337,6 +2338,17 @@ static struct config_int ConfigureNamesInt[] =
23372338
NULL, NULL, NULL
23382339
},
23392340

2341+
{
2342+
{"shared_memory_size", PGC_INTERNAL, RESOURCES_MEM,
2343+
gettext_noop("Shows the size of the server's main shared memory area (rounded up to the nearest MB)."),
2344+
NULL,
2345+
GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE | GUC_UNIT_MB
2346+
},
2347+
&shared_memory_size_mb,
2348+
0, 0, INT_MAX,
2349+
NULL, NULL, NULL
2350+
},
2351+
23402352
{
23412353
{"temp_buffers", PGC_USERSET, RESOURCES_MEM,
23422354
gettext_noop("Sets the maximum number of temporary buffers used by each session."),

src/include/storage/ipc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,6 @@ extern PGDLLIMPORT shmem_startup_hook_type shmem_startup_hook;
7979

8080
extern Size CalculateShmemSize(int *num_semaphores);
8181
extern void CreateSharedMemoryAndSemaphores(void);
82+
extern void InitializeShmemGUCs(void);
8283

8384
#endif /* IPC_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy