diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2011-01-15 16:27:40 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2011-01-15 16:38:21 +0200 |
commit | 8f5d65e916796aaee1bf7dd66daf45ca56cd13be (patch) | |
tree | c9279279b9702d580cfd38c447e4ca63c797cff8 /src/backend/storage/ipc | |
parent | fcd810c69adf11b6ec1cff35359be0dd27662eff (diff) | |
download | postgresql-8f5d65e916796aaee1bf7dd66daf45ca56cd13be.tar.gz postgresql-8f5d65e916796aaee1bf7dd66daf45ca56cd13be.zip |
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 signaling
bgwriter to finish. This avoids race conditions between a base backup stopping
or starting, and bgwriter writing the shutdown checkpoint WAL record. We don't
want e.g the end-of-backup WAL record to be written after the shutdown
checkpoint.
Diffstat (limited to 'src/backend/storage/ipc')
-rw-r--r-- | src/backend/storage/ipc/pmsignal.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/backend/storage/ipc/pmsignal.c b/src/backend/storage/ipc/pmsignal.c index 155bd751bf2..391d6a6ea04 100644 --- a/src/backend/storage/ipc/pmsignal.c +++ b/src/backend/storage/ipc/pmsignal.c @@ -49,6 +49,8 @@ * * Actually there is a fourth state, WALSENDER. This is just like ACTIVE, * but carries the extra information that the child is a WAL sender. + * WAL senders too start in ACTIVE state, but switch to WALSENDER once they + * start streaming the WAL (and they never go back to ACTIVE after that). */ #define PM_CHILD_UNUSED 0 /* these values must fit in sig_atomic_t */ @@ -225,8 +227,25 @@ MarkPostmasterChildActive(void) Assert(slot > 0 && slot <= PMSignalState->num_child_flags); slot--; Assert(PMSignalState->PMChildFlags[slot] == PM_CHILD_ASSIGNED); - PMSignalState->PMChildFlags[slot] = - (am_walsender ? PM_CHILD_WALSENDER : PM_CHILD_ACTIVE); + PMSignalState->PMChildFlags[slot] = PM_CHILD_ACTIVE; +} + +/* + * MarkPostmasterChildWalSender - mark a postmaster child as a WAL sender + * process. This is called in the child process, sometime after marking the + * child as active. + */ +void +MarkPostmasterChildWalSender(void) +{ + int slot = MyPMChildSlot; + + Assert(am_walsender); + + Assert(slot > 0 && slot <= PMSignalState->num_child_flags); + slot--; + Assert(PMSignalState->PMChildFlags[slot] == PM_CHILD_ACTIVE); + PMSignalState->PMChildFlags[slot] = PM_CHILD_WALSENDER; } /* |