pgsql: Reject concurrent sequence refreshes.

From: Amit Kapila <akapila(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Reject concurrent sequence refreshes.
Date: 2026-07-15 10:25:46
Message-ID: E1wjwoD-000HjZ-1t@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Reject concurrent sequence refreshes.

'ALTER SUBSCRIPTION ... REFRESH SEQUENCES' can race with an already
running sequence synchronization worker. If a second refresh request
resets the synchronization state while the worker has already fetched
sequence values from the publisher but has not yet applied them to the
subscriber, the worker can overwrite the subscriber with stale values
and mark the synchronization as complete.

Avoid this race by rejecting 'ALTER SUBSCRIPTION ... REFRESH SEQUENCES'
when a sequence synchronization worker is already running for the
subscription. The command reports an error asking the user to rerun it
after the current synchronization completes.

Also add a wait for the re-added 'regress_s4' sequence to finish
synchronizing in 036_sequences.pl, so the subsequent test does not race
against its sequencesync worker.

Reported-by: Noah Misch <noah(at)leadboat(dot)com>
Author: vignesh C <vignesh21(at)gmail(dot)com>
Reviewed-by: Shveta Malik <shveta(dot)malik(at)gmail(dot)com>
Reviewed-by: Hayato Kuroda <kuroda(dot)hayato(at)fujitsu(dot)com>
Reviewed-by: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Backpatch-through: 19, where it was introduced
Discussion: https://postgr.es/m/20260710045217.f0.noahmisch@microsoft.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f38afa4abb04e85530c94b88daf11c089375daca

Modified Files
--------------
src/backend/commands/subscriptioncmds.c | 27 +++++++++++++++++++++++++++
src/test/subscription/t/036_sequences.pl | 4 ++++
2 files changed, 31 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2026-07-15 12:25:49 pgsql: Fix argument names in pg_clear_attribute_stats() errors
Previous Message Bruce Momjian 2026-07-15 09:51:36 pgsql: doc PG 19 relnotes: swap OAUTH hook and validator items