From cd13fd2f8d4549adca5ef12775a7b6a90810f0a1 Mon Sep 17 00:00:00 2001 From: Alexandre Felipe Date: Tue, 15 Sep 2026 07:42:16 +0100 Subject: [PATCH-v1] FIX missing lock in AlterSequence AlsterSequence was calling RelationSetNewRelfilenumber without any lock. RelationSetNewRelfilenumber already states that the caller must hold an exclusive lock. That line must be read as AccessExclusiveLock as opposed to ExclusiveLock. --- src/backend/commands/sequence.c | 6 ++++++ src/backend/utils/cache/relcache.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c index 551667650ba..459738f5bf8 100644 --- a/src/backend/commands/sequence.c +++ b/src/backend/commands/sequence.c @@ -489,6 +489,12 @@ AlterSequence(ParseState *pstate, AlterSeqStmt *stmt) /* If needed, rewrite the sequence relation itself */ if (need_seq_rewrite) { + /* + * RelationSetNewRelfilenumber destroys the existing relation file, + * so it conflicts with SELECT (AccessShareLock) + */ + LockRelationOid(relid, AccessExclusiveLock); + /* check the comment above nextval_internal()'s equivalent call. */ if (RelationNeedsWAL(seqrel)) GetTopTransactionId(); diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 541f30f0972..f74cdc6d6bb 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -3770,7 +3770,7 @@ RelationBuildLocalRelation(const char *relname, * remainder of the current transaction. This limits the usefulness to cases * such as TRUNCATE or rebuilding an index from scratch. * - * Caller must already hold exclusive lock on the relation. + * Caller must already hold access exclusive lock on the relation. */ void RelationSetNewRelfilenumber(Relation relation, char persistence) -- 2.53.0