Skip to content

Commit 7275899

Browse files
committed
Move synchronous_standbys_defined updates from WAL writer to BG writer.
This is advantageous because the BG writer is alive until much later in the shutdown sequence than WAL writer; we want to make sure that it's possible to shut off synchronous replication during a smart shutdown, else it might not be possible to complete the shutdown at all. Per very reasonable gripes from Fujii Masao and Simon Riggs.
1 parent f78ba0a commit 7275899

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/backend/postmaster/bgwriter.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include "miscadmin.h"
5656
#include "pgstat.h"
5757
#include "postmaster/bgwriter.h"
58+
#include "replication/syncrep.h"
5859
#include "storage/bufmgr.h"
5960
#include "storage/fd.h"
6061
#include "storage/ipc.h"
@@ -363,6 +364,9 @@ BackgroundWriterMain(void)
363364
if (RecoveryInProgress())
364365
ThisTimeLineID = GetRecoveryTargetTLI();
365366

367+
/* Do this once before starting the loop, then just at SIGHUP time. */
368+
SyncRepUpdateSyncStandbysDefined();
369+
366370
/*
367371
* Loop forever
368372
*/
@@ -389,6 +393,8 @@ BackgroundWriterMain(void)
389393
{
390394
got_SIGHUP = false;
391395
ProcessConfigFile(PGC_SIGHUP);
396+
/* update global shmem state for sync rep */
397+
SyncRepUpdateSyncStandbysDefined();
392398
}
393399
if (checkpoint_requested)
394400
{
@@ -704,6 +710,8 @@ CheckpointWriteDelay(int flags, double progress)
704710
{
705711
got_SIGHUP = false;
706712
ProcessConfigFile(PGC_SIGHUP);
713+
/* update global shmem state for sync rep */
714+
SyncRepUpdateSyncStandbysDefined();
707715
}
708716

709717
AbsorbFsyncRequests();

src/backend/postmaster/walwriter.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
#include "libpq/pqsignal.h"
5050
#include "miscadmin.h"
5151
#include "postmaster/walwriter.h"
52-
#include "replication/syncrep.h"
5352
#include "storage/bufmgr.h"
5453
#include "storage/fd.h"
5554
#include "storage/ipc.h"
@@ -217,9 +216,6 @@ WalWriterMain(void)
217216
*/
218217
PG_SETMASK(&UnBlockSig);
219218

220-
/* Do this once before starting the loop, then just at SIGHUP time. */
221-
SyncRepUpdateSyncStandbysDefined();
222-
223219
/*
224220
* Loop forever
225221
*/
@@ -241,8 +237,6 @@ WalWriterMain(void)
241237
{
242238
got_SIGHUP = false;
243239
ProcessConfigFile(PGC_SIGHUP);
244-
/* update global shmem state for sync rep */
245-
SyncRepUpdateSyncStandbysDefined();
246240
}
247241
if (shutdown_requested)
248242
{

src/backend/replication/syncrep.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,9 @@ SyncRepWakeQueue(bool all)
557557
}
558558

559559
/*
560-
* WAL writer calls this as needed to update the shared sync_standbys_defined
561-
* flag, so that backends don't remain permanently wedged if
562-
* synchronous_standby_names is unset. It's safe to check the current value
560+
* The background writer calls this as needed to update the shared
561+
* sync_standbys_defined flag, so that backends don't remain permanently wedged
562+
* if synchronous_standby_names is unset. It's safe to check the current value
563563
* without the lock, because it's only ever updated by one process. But we
564564
* must take the lock to change it.
565565
*/

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