pgsql: Avoid accumulating relation locks during sequence synchronizatio

From: Amit Kapila <akapila(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Avoid accumulating relation locks during sequence synchronizatio
Date: 2026-07-29 04:23:18
Message-ID: E1wovp8-00000000kky-11YJ@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Avoid accumulating relation locks during sequence synchronization.

While collecting the sequences to synchronize, the sequence sync worker
opened each INIT sequence with RowExclusiveLock and held it until the
transaction committed. With many such sequences, this could exhaust the
shared lock table and fail with "out of shared memory".

The worker only reads each sequence's identity (namespace and name) here
and needs it to stay stable while read, for which AccessShareLock is
enough, as it conflicts with the AccessExclusiveLock taken by DROP,
RENAME, and SET SCHEMA. Take that lock instead and release it as soon as
the identity is read. The later synchronization re-opens each sequence, so
it does not rely on the lock being retained.

Reported-by: Noah Misch <noah(at)leadboat(dot)com>
Author: vignesh C <vignesh21(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/c12c101b0846b1e6488f2dc986a852fbc6bf2e3b

Modified Files
--------------
src/backend/replication/logical/sequencesync.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2026-07-29 08:40:05 pgsql: Protect PGPROC lookup when terminating background workers
Previous Message Michael Paquier 2026-07-28 23:55:27 pgsql: Use more strlcpy() in two-phase transaction code