Re: pg_resetwal: add --cluster-state option

From: shihao zhong <zhong950419(at)gmail(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Michael Paquier <michael(at)paquier(dot)xyz>, David Steele <david(at)pgbackrest(dot)org>
Subject: Re: pg_resetwal: add --cluster-state option
Date: 2026-10-09 05:01:39
Message-ID: CAGRkXqSPa3hzHgXLXgGvKEiWFCeTq5UoPTrxYQLVYpAXu0smCw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Sho, Chao,

Thanks for looking. v2 is attached.

Sho Ito wrote:
> I noticed that an invalid value for `--cluster-state` directs the user
> to `--help`, but the help output doesn't list the accepted values.

Agreed, --help lists them now.

Chao Li wrote:
> * Print the previous recorded state alongside the new state before
> updating the control file.

pg_resetwal prints nothing on a real run, so I put this in --dry-run.
It now shows the stored state under "Current pg_control values", and
the new one under "Values to be changed". Both use the names the
option takes.

> * Provide an explicit mode to change only the cluster state, without
> doing other things.

I left this out. A wrong state can be fixed by running pg_resetwal -f
again with the right one. The WAL is already gone by then, so the
second reset loses nothing. I tried in-production, then -f with
shut-down, and the unlogged table kept its rows.

Without the reset it is a different tool, I think. For example,
setting shut-down on a crashed cluster would skip recovery while the
WAL is still there.

> With a non-default --cluster-state value, a cluster can enter
> recovery on its next startup and have its unlogged tables emptied.
> That affects the database contents, so this paragraph might need to
> be updated accordingly.

Right. That paragraph now says it does not hold when --cluster-state
sets a state other than shut-down.

Thanks,
Shihao

Attachment Content-Type Size
v2-0001-pg_resetwal-Add-cluster-state-option.patch application/octet-stream 7.7 KB
v2-0002-Test-pg_resetwal-cluster-state.patch application/octet-stream 2.3 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Paul A Jungwirth 2026-10-09 05:21:49 Re: addFkRecurseReferencing use unassigned fkconstraint->fk_with_period value
Previous Message Michael Paquier 2026-10-09 05:00:34 Re: WAL segment file descriptor leak on read errors can PANIC the server