agora inbox for pgsql-committers@postgresql.orghelp / color / mirror / Atom feed
pgsql: Handle concurrent sequence refreshes. 2+ messages / 1 participants [nested] [flat]
* pgsql: Handle concurrent sequence refreshes. @ 2026-07-20 05:51 Amit Kapila <akapila@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: Amit Kapila @ 2026-07-20 05:51 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Handle concurrent sequence refreshes. 'ALTER SUBSCRIPTION ... REFRESH SEQUENCES' can race with a running sequence synchronization worker. If the worker has fetched a sequence's value from the publisher but not yet marked it READY, a concurrent refresh that resets the sequence to INIT can be overwritten by the worker's stale value, silently losing the refresh request. Handle this by stopping any running sequence sync worker before resetting the sequences to INIT. This is race-free because AlterSubscription() already holds AccessExclusiveLock on the subscription object. That lock blocks a running worker's UpdateSubscriptionRelState(), which takes AccessShareLock on the object, and also any worker the apply worker re-launches, because a new worker takes AccessShareLock on the object in InitializeLogRepWorker() before it reads pg_subscription_rel. Such a worker cannot act on the sequence states until the refresh commits, by which time they are reset to INIT and it will synchronize the latest publisher values. Reported-by: Noah Misch <noah@leadboat.com> Author: Amit Kapila <amit.kapila16@gmail.com> Reviewed-by: vignesh C <vignesh21@gmail.com> Reviewed-by: Shveta Malik <shveta.malik@gmail.com> Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com> Backpatch-through: 19 Discussion: https://postgr.es/m/20260710045217.f0.noahmisch@microsoft.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/45cf7b1e5bf923ca48dfd9aa5001bdd0630d11c3 Modified Files -------------- src/backend/commands/subscriptioncmds.c | 67 ++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 17 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
* pgsql: Handle concurrent sequence refreshes. @ 2026-07-20 05:51 Amit Kapila <akapila@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: Amit Kapila @ 2026-07-20 05:51 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Handle concurrent sequence refreshes. 'ALTER SUBSCRIPTION ... REFRESH SEQUENCES' can race with a running sequence synchronization worker. If the worker has fetched a sequence's value from the publisher but not yet marked it READY, a concurrent refresh that resets the sequence to INIT can be overwritten by the worker's stale value, silently losing the refresh request. Handle this by stopping any running sequence sync worker before resetting the sequences to INIT. This is race-free because AlterSubscription() already holds AccessExclusiveLock on the subscription object. That lock blocks a running worker's UpdateSubscriptionRelState(), which takes AccessShareLock on the object, and also any worker the apply worker re-launches, because a new worker takes AccessShareLock on the object in InitializeLogRepWorker() before it reads pg_subscription_rel. Such a worker cannot act on the sequence states until the refresh commits, by which time they are reset to INIT and it will synchronize the latest publisher values. Reported-by: Noah Misch <noah@leadboat.com> Author: Amit Kapila <amit.kapila16@gmail.com> Reviewed-by: vignesh C <vignesh21@gmail.com> Reviewed-by: Shveta Malik <shveta.malik@gmail.com> Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com> Backpatch-through: 19 Discussion: https://postgr.es/m/20260710045217.f0.noahmisch@microsoft.com Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/a8c9d2be280443956cf2740017bf869ccdc562c3 Modified Files -------------- src/backend/commands/subscriptioncmds.c | 67 ++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 17 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-07-20 05:51 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-07-20 05:51 pgsql: Handle concurrent sequence refreshes. Amit Kapila <akapila@postgresql.org> 2026-07-20 05:51 pgsql: Handle concurrent sequence refreshes. Amit Kapila <akapila@postgresql.org>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox