| From: | Jan Nidzwetzki <jan(at)planetscale(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | pg_rewind --source-pgdata ignores minRecoveryPoint of a stopped standby |
| Date: | 2026-11-27 19:23:01 |
| Message-ID: | 51de3e6e-01de-4740-ad11-1bf69ff0d68d@planetscale.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Hackers,
When you run pg_rewind with --source-pgdata and the source is a cleanly
stopped standby, it sets the target's minRecoveryPoint to the source's
last restartpoint instead of the source's minRecoveryPoint. This causes
the target to be marked consistent too soon.
Problem
=======
For a local source, pg_rewind assumes there was a shutdown checkpoint
and uses the latest checkpoint location as the point the target must
replay to. But it also accepts a source that is shut down in recovery,
and in that case, the standby's data files include changes up to its
minRecoveryPoint. When using --source-server, pg_rewind already uses
minRecoveryPoint for a standby source.
To reproduce this, it is enough that the source standby replays a
transaction after its last restartpoint before it is stopped. In my
test, it replayed a CHECKPOINT followed by a transaction:
Latest checkpoint location: 0/030001A8
Minimum recovery ending location: 0/03000388
After pg_rewind, the control file of the target contains the checkpoint
location of the source, not its minRecoveryPoint:
Minimum recovery ending location: 0/030001A8
This is important if recovery ends at the consistency point, such as
with recovery_target = 'immediate'. In this case, the target has blocks
from the source that are newer than the WAL it has replayed. As a
result, a transaction that was not replayed can become partially
visible: once a new transaction on the target gets the same xid, its
changes in the copied blocks show up, while its changes in other blocks
are missing.
Patch
=====
The attached patch makes pg_rewind use the source's minRecoveryPoint if
it is later than the last checkpoint. It also adds a TAP test for this case.
Comments welcome.
Best regards
Jan
--
Jan Nidzwetzki
PlanetScale
| Attachment | Content-Type | Size |
|---|---|---|
| 0001-pg_rewind-Use-minRecoveryPoint-of-a-local-standby-so.patch | text/plain | 6.6 KB |
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Tom Lane | 2026-11-27 17:18:56 | Re: Add counted_by attribute |