Repository navigation
Add standby_clean_stop.sh: stop a crashed standby in standby mode - #75
Merged
Merged
Conversation
pg-coordinator runs /scripts/standby_clean_stop.sh on a standby that was not
shut down cleanly ("in archive recovery"), instead of single-user crash
recovery, which recovers the standby as a primary on the leader's timeline and
can silently skip the leader's WAL. The script starts the server in standby mode
with no upstream and hot_standby=off, waits for a consistent state, and stops it
with -m fast, so the control file says "shut down in recovery" and no WAL is
written.
It is POSIX sh (busybox ash, dash and bash), finds nss_wrapper under /usr/lib
and /usr/lib64 for an arbitrary uid, and defaults its arguments from $PGDATA and
PG_VERSION.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: souravbiswassanto <saurov@appscode.com>
pg_ctl stop -w waits for the pid file to go away, re-reading it every 100 ms. When the container's start loop started a standby the moment our server exited, pg_ctl waited on that server for the full timeout and then immediate-stopped it. When another server was already running, pg_ctl start failed and the script fast-stopped that server and reported success. Both were reproduced on alpine, bookworm and CentOS Stream 9. The server is now tagged with cluster_name=pgc-standby-clean-stop and identified by its PID and command line. It is stopped with SIGINT (fast) to that PID, the wait is for that process, and SIGQUIT (immediate) is a last resort for that PID only. A server this step did not start is never signalled: it is reported as OTHER_RUNNING=1 and the caller retries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: souravbiswassanto <saurov@appscode.com>
Signed-off-by: souravbiswassanto <saurov@appscode.com>
…'s copy) Signed-off-by: souravbiswassanto <saurov@appscode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
pg-coordinator used to crash-recover a hard-killed standby ("in archive recovery") in single-user mode:
standby.signaland recovers the node as a primary on the timeline it shares with the leader.Change
Add
scripts/standby_clean_stop.sh. The init container copies it to/scripts, next to the other scripts the coordinator runs. It:hot_standby=off;-m fast.The control file then says "shut down in recovery", and no WAL is written.
sh: busybox ash (alpine), dash (debian), bash (CentOS Stream 9).libnss_wrapper.sounder/usr/liband/usr/lib64.<pgdata> <pg-major> <timeout>default to$PGDATA,PG_VERSIONand 300 s.pg-coordinator#293 runs this copy when it exists, and its embedded copy otherwise.
Testing
Tested on alpine 17.9, bookworm 17.9 and Postgres Enterprise 17.11 on CentOS Stream 9:
In each image: a primary and a streaming standby with
archive_mode=always. The standby is hard-killed while the leader writes and changes a role password, then the script runs. Each ended "shut down in recovery" on the same timeline, and after a restart it was byte-identical to the primary,pg_authidincluded.On KubeDB, with pg-coordinator#293: the crashed-standby step runs this script from
/scriptson all three distros. The standby rejoins and every pod has the same data.Stops only the server it started (second commit):
pg_ctl stop -wwaits for the pid file to disappear, re-reading it every 100 ms. If another server starts the moment ours exits (for example the container start loop), it waits on that server for the full timeout and then immediate-stops it. If another server is already running, the old script fast-stopped it and reported success.cluster_name=pgc-standby-clean-stop, identifies it by PID and command line, and stops that PID only: SIGINT, with SIGQUIT as a last resort. It waits on that process, not the pid file. Any other server is left alone and reported asOTHER_RUNNING=1, and the coordinator retries.