Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8f5d65e

Browse files
committed
Treat a WAL sender process that hasn't started streaming yet as a regular
backend, as far as the postmaster shutdown logic is concerned. That means,fast shutdown will wait for WAL sender processes to exit before signalingbgwriter to finish. This avoids race conditions between a base backup stoppingor starting, and bgwriter writing the shutdown checkpoint WAL record. We don'twant e.g the end-of-backup WAL record to be written after the shutdowncheckpoint.
1 parentfcd810c commit8f5d65e

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

‎src/backend/replication/walsender.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,16 @@ StartReplication(StartReplicationCmd * cmd)
315315
{
316316
StringInfoDatabuf;
317317

318+
/*
319+
* Let postmaster know that we're streaming. Once we've declared us as
320+
* a WAL sender process, postmaster will let us outlive the bgwriter and
321+
* kill us last in the shutdown sequence, so we get a chance to stream
322+
* all remaining WAL at shutdown, including the shutdown checkpoint.
323+
* Note that there's no going back, and we mustn't write any WAL records
324+
* after this.
325+
*/
326+
MarkPostmasterChildWalSender();
327+
318328
/*
319329
* Check that we're logging enough information in the WAL for
320330
* log-shipping.

‎src/backend/storage/ipc/pmsignal.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
*
5050
* Actually there is a fourth state, WALSENDER. This is just like ACTIVE,
5151
* but carries the extra information that the child is a WAL sender.
52+
* WAL senders too start in ACTIVE state, but switch to WALSENDER once they
53+
* start streaming the WAL (and they never go back to ACTIVE after that).
5254
*/
5355

5456
#definePM_CHILD_UNUSED0/* these values must fit in sig_atomic_t */
@@ -225,8 +227,25 @@ MarkPostmasterChildActive(void)
225227
Assert(slot>0&&slot <=PMSignalState->num_child_flags);
226228
slot--;
227229
Assert(PMSignalState->PMChildFlags[slot]==PM_CHILD_ASSIGNED);
228-
PMSignalState->PMChildFlags[slot]=
229-
(am_walsender ?PM_CHILD_WALSENDER :PM_CHILD_ACTIVE);
230+
PMSignalState->PMChildFlags[slot]=PM_CHILD_ACTIVE;
231+
}
232+
233+
/*
234+
* MarkPostmasterChildWalSender - mark a postmaster child as a WAL sender
235+
* process. This is called in the child process, sometime after marking the
236+
* child as active.
237+
*/
238+
void
239+
MarkPostmasterChildWalSender(void)
240+
{
241+
intslot=MyPMChildSlot;
242+
243+
Assert(am_walsender);
244+
245+
Assert(slot>0&&slot <=PMSignalState->num_child_flags);
246+
slot--;
247+
Assert(PMSignalState->PMChildFlags[slot]==PM_CHILD_ACTIVE);
248+
PMSignalState->PMChildFlags[slot]=PM_CHILD_WALSENDER;
230249
}
231250

232251
/*

‎src/include/storage/pmsignal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ extern bool ReleasePostmasterChildSlot(int slot);
4848
externboolIsPostmasterChildWalSender(intslot);
4949
externvoidMarkPostmasterChildActive(void);
5050
externvoidMarkPostmasterChildInactive(void);
51+
externvoidMarkPostmasterChildWalSender(void);
5152
externboolPostmasterIsAlive(boolamDirectChild);
5253

5354
#endif/* PMSIGNAL_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp