Hi hackers, pg_resetwal always marks the cluster as shut down in pg_control. Michael suggested in [1] an option to store another state, and David asked for a separate thread [2]. So here it is.
The patch adds --cluster-state. It takes shut-down, which is the
default, shut-down-in-recovery, shutting-down, in-crash-recovery,
in-archive-recovery or in-production. DB_STARTUP is left out because
the server refuses to start with it.
With any state other than shut-down, the next start goes through crash
recovery. There is no WAL to replay, but the other steps still run.
What I can show is unlogged tables. After an immediate stop and
pg_resetwal -f, the server starts as if it was shut down cleanly, and
an unlogged table keeps what was on disk:
LOG: database system was shut down at ...
$ psql -Atc "select count(*) from u"
1000
With --cluster-state=in-production the table is reset:
LOG: database system was not properly shut down; automatic recovery in
progress
LOG: redo is not required
$ psql -Atc "select count(*) from u"
0
That is the only use I have so far. Michael, what did you have in mind
for it?
[1] https://postgr.es/m/[email protected]
[2] https://postgr.es/m/[email protected]
Thanks,
Shihao
v1-0001-pg_resetwal-Add-cluster-state-option.patch
Description: Binary data
v1-0002-Test-pg_resetwal-cluster-state.patch
Description: Binary data
