]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Avoid accumulating relation locks during sequence synchronization.
authorAmit Kapila <akapila@postgresql.org>
Wed, 29 Jul 2026 04:09:59 +0000 (09:39 +0530)
committerAmit Kapila <akapila@postgresql.org>
Wed, 29 Jul 2026 04:09:59 +0000 (09:39 +0530)
commite46c2a65710f021e25bc0fcf404dd00c86aec1d7
tree46f1a53e101718b7846388e19a1a2602572b0612
parent9740c68ff7aa5d5a2d40c3ff0172467b38a17df8
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@leadboat.com>
Author: vignesh C <vignesh21@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Backpatch-through: 19, where it was introduced
Discussion: https://postgr.es/m/20260710045217.f0.noahmisch@microsoft.com
src/backend/replication/logical/sequencesync.c