|
43 | 43 | #include"postmaster/autovacuum.h"
|
44 | 44 | #include"replication/slot.h"
|
45 | 45 | #include"replication/syncrep.h"
|
| 46 | +#include"replication/walsender.h" |
46 | 47 | #include"storage/condition_variable.h"
|
47 | 48 | #include"storage/standby.h"
|
48 | 49 | #include"storage/ipc.h"
|
@@ -147,8 +148,9 @@ ProcGlobalSemas(void)
|
147 | 148 | * running out when trying to start another backend is a common failure.
|
148 | 149 | * So, now we grab enough semaphores to support the desired max number
|
149 | 150 | * of backends immediately at initialization --- if the sysadmin has set
|
150 |
| - * MaxConnections, max_worker_processes, or autovacuum_max_workers higher |
151 |
| - * than his kernel will support, he'll find out sooner rather than later. |
| 151 | + * MaxConnections, max_worker_processes, max_wal_senders, or |
| 152 | + * autovacuum_max_workers higher than his kernel will support, he'll |
| 153 | + * find out sooner rather than later. |
152 | 154 | *
|
153 | 155 | * Another reason for creating semaphores here is that the semaphore
|
154 | 156 | * implementation typically requires us to create semaphores in the
|
@@ -180,6 +182,7 @@ InitProcGlobal(void)
|
180 | 182 | ProcGlobal->freeProcs=NULL;
|
181 | 183 | ProcGlobal->autovacFreeProcs=NULL;
|
182 | 184 | ProcGlobal->bgworkerFreeProcs=NULL;
|
| 185 | +ProcGlobal->walsenderFreeProcs=NULL; |
183 | 186 | ProcGlobal->startupProc=NULL;
|
184 | 187 | ProcGlobal->startupProcPid=0;
|
185 | 188 | ProcGlobal->startupBufferPinWaitBufId=-1;
|
@@ -253,13 +256,20 @@ InitProcGlobal(void)
|
253 | 256 | ProcGlobal->autovacFreeProcs=&procs[i];
|
254 | 257 | procs[i].procgloballist=&ProcGlobal->autovacFreeProcs;
|
255 | 258 | }
|
256 |
| -elseif (i<MaxBackends) |
| 259 | +elseif (i<MaxConnections+autovacuum_max_workers+1+max_worker_processes) |
257 | 260 | {
|
258 | 261 | /* PGPROC for bgworker, add to bgworkerFreeProcs list */
|
259 | 262 | procs[i].links.next= (SHM_QUEUE*)ProcGlobal->bgworkerFreeProcs;
|
260 | 263 | ProcGlobal->bgworkerFreeProcs=&procs[i];
|
261 | 264 | procs[i].procgloballist=&ProcGlobal->bgworkerFreeProcs;
|
262 | 265 | }
|
| 266 | +elseif (i<MaxBackends) |
| 267 | +{ |
| 268 | +/* PGPROC for walsender, add to walsenderFreeProcs list */ |
| 269 | +procs[i].links.next= (SHM_QUEUE*)ProcGlobal->walsenderFreeProcs; |
| 270 | +ProcGlobal->walsenderFreeProcs=&procs[i]; |
| 271 | +procs[i].procgloballist=&ProcGlobal->walsenderFreeProcs; |
| 272 | +} |
263 | 273 |
|
264 | 274 | /* Initialize myProcLocks[] shared memory queues. */
|
265 | 275 | for (j=0;j<NUM_LOCK_PARTITIONS;j++)
|
@@ -311,6 +321,8 @@ InitProcess(void)
|
311 | 321 | procgloballist=&ProcGlobal->autovacFreeProcs;
|
312 | 322 | elseif (IsBackgroundWorker)
|
313 | 323 | procgloballist=&ProcGlobal->bgworkerFreeProcs;
|
| 324 | +elseif (am_walsender) |
| 325 | +procgloballist=&ProcGlobal->walsenderFreeProcs; |
314 | 326 | else
|
315 | 327 | procgloballist=&ProcGlobal->freeProcs;
|
316 | 328 |
|
@@ -341,6 +353,11 @@ InitProcess(void)
|
341 | 353 | * in the autovacuum case?
|
342 | 354 | */
|
343 | 355 | SpinLockRelease(ProcStructLock);
|
| 356 | +if (am_walsender) |
| 357 | +ereport(FATAL, |
| 358 | +(errcode(ERRCODE_TOO_MANY_CONNECTIONS), |
| 359 | +errmsg("number of requested standby connections exceeds max_wal_senders (currently %d)", |
| 360 | +max_wal_senders))); |
344 | 361 | ereport(FATAL,
|
345 | 362 | (errcode(ERRCODE_TOO_MANY_CONNECTIONS),
|
346 | 363 | errmsg("sorry, too many clients already")));
|
|