pg_resetwal: add --cluster-state option

From: shihao zhong <zhong950419(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, David Steele <david(at)pgbackrest(dot)org>
Subject: pg_resetwal: add --cluster-state option
Date: 2026-10-05 04:03:07
Message-ID: CAGRkXqRH=xzB7svv-xFRF=6Lexo8tX0T4XX207uPAwuLys-Kcw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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/ar8mhs05SzC4hjmu@paquier.xyz
[2] https://postgr.es/m/10a44059-c8f8-4bb5-8950-63390eedfaa0@pgbackrest.org

Thanks,
Shihao

Attachment Content-Type Size
v1-0001-pg_resetwal-Add-cluster-state-option.patch application/octet-stream 5.1 KB
v1-0002-Test-pg_resetwal-cluster-state.patch application/octet-stream 1.9 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2026-10-05 04:12:07 Re: Stabilize recovery conflict stats checks in 031_recovery_conflict.pl
Previous Message shihao zhong 2026-10-05 03:59:37 Re: examine_variable ignored CollateExpr