| From: | Osama Abdul Qader <osamaabdulqaderpostgres(at)gmail(dot)com> |
|---|---|
| To: | Jan Nidzwetzki <jan(at)planetscale(dot)com> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, hlinnaka(at)iki(dot)fi |
| Subject: | Re: pg_rewind reports "no rewind required" due to stale minRecoveryPoint |
| Date: | 2026-11-27 13:14:30 |
| Message-ID: | CAAprpiCo3LWcrN75YAakiHssNnTS89tWT=f30JWnc_U56ohE3g@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Jan
On Fri, 27 Nov 2026 at 18:30, Jan Nidzwetzki <jan(at)planetscale(dot)com> wrote:
> Hi Hackers,
>
> While working on a pg_rewind issue [1], I found that pg_rewind sometimes
> reports "no rewind required" for a standby that was cleanly stopped
> after replaying WAL past the divergence point. The standby then cannot
> follow the new primary:
>
> LOG: new timeline 2 forked off current database system timeline 1
> before current recovery point 0/03000138
>
>
> Problem
> =======
>
> pg_rewind uses minRecoveryPoint as the end of WAL for a standby. When
> shutting down, CreateRestartPoint() sets it to the replay position only
> if the restartpoint is skipped. If a restartpoint is performed, it
> assumes flushing the buffers will advance it. This only happens if a
> written page has a newer LSN, such as a data page or a pg_xact page with
> a commit replayed in hot standby. Many records leave no such page
> behind, such as an abort, PREPARE TRANSACTION, a restore point, a WAL
> switch, or a standby snapshot. If only these records were replayed since
> minRecoveryPoint was last updated, it remains behind the replay position.
>
> To reproduce this, set up a primary with two standbys, S1 and S2.
> Restart S2, run CHECKPOINT on the primary, and promote S1. Next, run
> "BEGIN; SELECT pg_current_xact_id(); ROLLBACK;" on the primary, let S2
> replay the abort, stop S2, and then run pg_rewind on S2 using S1 as the
> source:
>
> pg_rewind: servers diverged at WAL location 0/03000110 on timeline 1
> pg_rewind: no rewind required
>
> The control file of S2 has minRecoveryPoint at 0/03000110, while the
> replayed abort ends at 0/03000138.
>
> If hot_standby is off on S2, a commit record acts the same way: after a
> COMMIT PREPARED that only S2 replays, pg_rewind also reports "no rewind
> required", pg_xact on S2 shows the transaction as committed, and it is
> still prepared on S1.
>
>
> Patch
> =====
>
> The attached patch updates minRecoveryPoint to the replay position at
> every shutdown restartpoint, just like the skipped path does. It also
> adds the steps above as a TAP test.
>
> BUG #18575 [2] shows the same symptom, but it looks like the standby
> received the WAL past the divergence point without replaying it before
> shutdown. This patch does not affect that case. In that thread, Heikki
> suggested that "perhaps a fast shutdown of a standby server should
> update minRecoveryPoint before exiting" [3], and this patch does that
> for the path that did not do so yet.
>
> Any comments?
>
> Best regards
> Jan
>
>
> URLs
> =====
> [1]
>
> https://www.postgresql.org/message-id/CAHebB-qQZaE9yhtUhMMS4ausPYp2PN%2BXyyhN7fCNe43x%3D-o8Ew%40mail.gmail.com
> [2]
>
> https://www.postgresql.org/message-id/18575-1b9b3b60e2a480de%40postgresql.org
> [3]
>
> https://www.postgresql.org/message-id/e08235e3-b216-4bf3-8a9a-8ea819ae105e%40iki.fi
>
>
> --
> Jan Nidzwetzki
> PlanetScale
>
I'm interested in contributing and reviewing the patch, I'll start
reviewing it once I'm at my den.
Best Regards,
Osama Abdul Qader
Independent contributor
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andrey Borodin | 2026-11-27 13:25:29 | Re: Set 1s WaitLatch timeout if standby limit has expired in ResolveRecoveryConflictWithBufferPin |
| Previous Message | Abraham Pérez | 2026-11-27 13:13:13 | Re: Reject ADD CONSTRAINT NOT NULL if name mismatches existing domain not-null constraint |