| From: | Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> |
|---|---|
| To: | Jan Nidzwetzki <jan(at)planetscale(dot)com>, Tom Pang <tom(at)planetscale(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | pg_rewind accepts a standby target that ran with wal_log_hints = off |
| Date: | 2026-11-28 11:07:59 |
| Message-ID: | CAN4CZFPN9_Lpd9f4MnMYXAHLam0pnbJiszFKVYXt8qee4GC2ww@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hello
> And while testing this I found a different issue: pg_rewind can't
> detect properly a mixed wal_log_hint_bits cluster if data checksums
> are also off, and operates in scenarios it shouldn't be; I'll create a
> separate thread about that
This is that separate thread I promised in [1].
pg_rewind refuses a target without data checksums or wal_log_hints,
based on the target's pg_control. On a standby that field is the
primary's value (base backup + XLOG_PARAMETER_CHANGE replay), but hint
bits are written according to the standby's own setting. So a standby
with wal_log_hints = off behind a primary with on is accepted.
Repro, all nodes without checksums:
1. primary A with wal_log_hints = on, standbys B and C, C with
wal_log_hints = off
2. open a transaction on A and insert a row, CHECKPOINT
3. promote B
4. commit on A, C replays it
5. CHECKPOINT on A and C (C's minRecoveryPoint has to pass the
commit), a SELECT on C sets HEAP_XMIN_COMMITTED, CHECKPOINT on A and C
again to write the page out
6. stop C, pg_rewind it from B
pg_rewind succeeds, and the row is visible on C but not on B.
With the attached patch the field tracks the standby's own setting:
* starting archive recovery with wal_log_hints = off clears it
* replaying XLOG_PARAMETER_CHANGE no longer sets it
* promotion sets it to the current value as before
It is only cleared during recovery, never set. Storing the current
value at every start isn't enough: if C is restarted with on before
the rewind, the hint bits are still on disk and it would be accepted.
The downside is that turning wal_log_hints on later isn't enough for
an existing standby, it has to be promoted or re-created before
pg_rewind accepts it. Today restarting the primary with on is enough
for all of its standbys, whatever they ran with before. I think that's
the right tradeoff, but I'm not sure everybody agrees?
Not solved by this patch: a primary that ran with off and was
restarted with on before the rewind has the same problem, as described
in [2]. And if wal_log_hints becomes reloadable as proposed in that
thread, checking it at the start of recovery isn't enough.
[1]: https://www.postgresql.org/message-id/CAN4CZFNXY4C7KyOE2ZFdc%3DL6-i-6bkE%2Bye8o9Y_L1x_DbfG_6A%40mail.gmail.com
[2]: https://www.postgresql.org/message-id/CAHza6qegmyONRMZspxYro7hbRtp_UrFShY%3DhD6x%3DQEwAydumrw%40mail.gmail.com
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Track-a-standby-s-own-wal_log_hints-in-pg_control.patch | application/octet-stream | 11.0 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Zhijie Hou | 2026-11-28 11:18:43 | Re: logical decoding: removing change_useless_for_repack() |
| Previous Message | Manu | 2026-11-28 09:23:19 | Re: Dropping a composite attribute causes data integrity violations |