Open pg_rewind issues

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Jan Nidzwetzki <jan(at)planetscale(dot)com>, Tom Pang <tom(at)planetscale(dot)com>, Alena Vinter <dlaaren8(at)gmail(dot)com>, Stepan Neretin <slpmcf(at)gmail(dot)com>, Soumyadeep Chakraborty <soumyadeep2007(at)gmail(dot)com>, Mats Kindahl <mats(dot)kindahl(at)gmail(dot)com>, Srinath Reddy Sadipiralla <srinath2133(at)gmail(dot)com>, Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>, Andrey Borodin <x4mmm(at)yandex-team(dot)ru>
Subject: Open pg_rewind issues
Date: 2026-11-28 13:20:28
Message-ID: CAN4CZFOs9x2mA7pfziCQvWgCayyx7_8H05NzADAa2x-WBrQiqg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello

There are many pg_rewind bug reports and patches open at the moment in
separate threads, and several of them are about the same few
questions: where the WAL of a standby target ends, what its control
file can tell, and which WAL stays on the target.

I was concerned that it's difficult to see an 'overview' picture with
all the small threads, and I also wanted to make sure that the
combination of these threads would work well together.

I tried to find all related threads, combine them locally on a single
branch, and do multiple LLM review/testing passes on them, and also a
manual review of the combined branch.

I am listing all of them here, so anybody who wants to contribute to
the pg_rewind fixing effort can easily find them.

* Hint bits set on a standby can reach disk on pages pg_rewind doesn't
copy, and the rewound node shows different rows than the source.
Reported by Tom Pang, reproduced back to 14. Jan's v3 already has
multiple reviews. It uses the hint bit API on 19, older branches need
something else.

https://postgr.es/m/CAHebB-qQZaE9yhtUhMMS4ausPYp2PN%2BXyyhN7fCNe43x%3D-o8Ew%40mail.gmail.com

* pg_rewind accepts a standby that ran with wal_log_hints = off behind
a primary with on, because pg_control on a standby has the primary's
value. The fix above relies on these being refused. My v1 tracks the
standby's own setting, with the open question if it's acceptable that
enabling wal_log_hints later doesn't help an existing standby.

https://postgr.es/m/CAN4CZFPN9_Lpd9f4MnMYXAHLam0pnbJiszFKVYXt8qee4GC2ww%40mail.gmail.com

* pg_rewind says "no rewind required" for a standby that replayed past
the fork, because minRecoveryPoint is behind. Jan's patch updates it
at every shutdown restartpoint, which Adam Lee proposed earlier this
year and Michael and Horiguchi-san didn't like. I proposed an
alternative, to let pg_rewind find the end of the target's WAL, today.

https://postgr.es/m/0491e46f-a1c3-48db-b171-705ca95c8263%40planetscale.com

* Same answer for a standby that received WAL past the fork but didn't
replay it (BUG #18575). When started, it replays its local WAL and can
never follow the new primary. Heikki's patches from 2024 don't apply
anymore. Jan's patch doesn't cover this, the PoC above does.

https://postgr.es/m/18575-1b9b3b60e2a480de%40postgresql.org

* The WAL segment kept on the target since 90bcc7c2db1 still has the
target's old WAL after the fork. If the source already recycled its
segment of the new timeline, recovery replays it. Alena's follow-up
patch has a similar problem. I sent a follow up to the original thread
today, as this was one of the issues discovered by the LLM-reviews.

https://postgr.es/m/CAN4CZFOF7URxB_%3DjL9g%3Dg-MBOmWZGP3RfQuURGRB6ozWkmBumw%40mail.gmail.com

* With --source-pgdata and a stopped standby as source, the target is
marked consistent too early. Jan's patch has no reviews yet.

https://postgr.es/m/51de3e6e-01de-4740-ad11-1bf69ff0d68d%40planetscale.com

* A rewound node that is started without the WAL up to
minRecoveryPoint opens anyway. My patch is Ready for Committer, but I
found that the check only works for the first start, the backup label
is gone for the second one. I sent a v2 today.

https://postgr.es/m/CAN4CZFPFeAV2%2BkBqez2WhQJ25%2BBcTcx7CZ68FsSq-xbFhXQbxQ%40mail.gmail.com

* A standby that crashes during promotion, after standby.signal is
removed but before pg_control has the new timeline, comes back as a
primary on the old timeline, and pg_rewind does nothing. Soumyadeep
has a test for it, there is no fix yet.

https://postgr.es/m/CAE-ML%2B8nkN%3DX3LiQ0-7cGQyQ3W3ncsrh2jKMPgk-SiNQPY%2BX_A%40mail.gmail.com

* Two independent promotions can get the same timeline ID, and
pg_rewind can't tell them apart (BUG #19477). Mats' v9 adds a UUID to
the history file. The code was reviewed, but the discussion in the
thread is still open.

https://postgr.es/m/CAN305gBeJr8m7ZRW9mH0zakEFR4hDUPDo8fJRKJOHWMORG5_Bg%40mail.gmail.com

* Three small ones that look ready: Stepan's removal of the bogus
Assert(target_wal_endrec == divergerec), Peter's buffer size fix, and
Ayush's v2 that errors out on a file that vanished during traversal.

https://postgr.es/m/CA%2BYyo5Raa0ePMeN64EPEBwt5n9T2FUr%3D%2BO3-LcnbO_5CJuaTGw%40mail.gmail.com
https://postgr.es/m/e0d69580-4001-4c43-9c71-284d5354e9f1%40eisentraut.org
https://postgr.es/m/CAJTYsWUt%2B7PB6kAiO3YM9XHSr-eZkRTwTgC%2BPU5Vd%2BoVhZSkUg%40mail.gmail.com

* Srinath's POC scans the WAL of an unclean target instead of running
crash recovery on it. It's a feature, but it rewrites code that
several patches above touch, and its scan is close to what the "no
rewind required" items need.

https://postgr.es/m/CAFC%2Bb6pztjF8AiM%3DGOs%3DSeNOYLpZnUSSMJsRKKZdf-MKJj22VQ%40mail.gmail.com

Most of these have a reproducer and a patch, and as I wrote in the
beginning, many of them are waiting for the same decisions: what
minRecoveryPoint of a stopped standby means, if pg_rewind should trust
the control file or read the WAL, and how much of this is
backpatchable.

I think it is useful if we can look at them together. Perhaps these
issues and questions are easier to figure out if we look at them
together instead of focusing on one isolated problem at a time.

Browse pgsql-hackers by date

  From Date Subject
Next Message Kirill Reshke 2026-11-28 13:22:25 Re: Set 1s WaitLatch timeout if standby limit has expired in ResolveRecoveryConflictWithBufferPin
Previous Message Zsolt Parragi 2026-11-28 12:44:10 Re: Bug? pg_rewind produces unusable but starting database with standby recovery