Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 28f6e20

Browse files
committed
Fix shmem allocation size.
MaxBackends is still 0 when _PG_init() is called, which means that we don't request enough memory in RequestAddinShmemSpace(), while the rest of the code sees (and allocate) a correct value. It's technically usually not a problem as postgres adds an extra 100kB of memory for small unaccounted memory usage, but it's better to avoid relying on it too much. Note that the value is still not guaranteed to be exact as other modules _PG_init() could later change the underlying GUCs, but there is not available API to handle that case accurately.
1 parent 59cfadb commit 28f6e20

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pg_wait_sampling.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#include "miscadmin.h"
1818
#include "optimizer/planner.h"
1919
#include "pgstat.h"
20+
#include "postmaster/autovacuum.h"
21+
#if PG_VERSION_NUM >= 120000
22+
#include "replication/walsender.h"
23+
#endif
2024
#include "storage/ipc.h"
2125
#include "storage/pg_shmem.h"
2226
#include "storage/procarray.h"
@@ -75,7 +79,12 @@ get_max_procs_count(void)
7579
int count = 0;
7680

7781
/* MyProcs, including autovacuum workers and launcher */
78-
count += MaxBackends;
82+
count += MaxConnections + autovacuum_max_workers + 1
83+
+ max_worker_processes
84+
#if PG_VERSION_NUM >= 120000
85+
+ max_wal_senders
86+
#endif
87+
+ 1;
7988
/* AuxiliaryProcs */
8089
count += NUM_AUXILIARY_PROCS;
8190
/* Prepared xacts */

0 commit comments

Comments
 (0)