Content-Length: 268929 | pFad | http://github.com/postgrespro/postgres/commit/f88cdb36c457f673a1966a22883ce47e565a37db

27 Lock owned sequences during ALTER TABLE SET { LOGGED | UNLOGGED }. · postgrespro/postgres@f88cdb3 · GitHub
Skip to content

Commit f88cdb3

Browse files
committed
Lock owned sequences during ALTER TABLE SET { LOGGED | UNLOGGED }.
These commands already make the persistence of owned sequences follow owned table persistence changes. They didn't lock those sequences. They lost the effect of nextval() calls that other sessions make after the ALTER TABLE command, before the ALTER TABLE transaction commits. Fix by acquiring the same lock that ALTER SEQUENCE SET { LOGGED | UNLOGGED } acquires. This might cause more deadlocks. Back-patch to v15, where commit 344d62f introduced unlogged sequences. Reviewed (in an earlier version) by Robert Haas. Discussion: https://postgr.es/m/20240611024525.9f.nmisch@google.com
1 parent d5f788b commit f88cdb3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/backend/commands/sequence.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,13 @@ SequenceChangePersistence(Oid relid, char newrelpersistence)
545545
Buffer buf;
546546
HeapTupleData seqdatatuple;
547547

548+
/*
549+
* ALTER SEQUENCE acquires this lock earlier. If we're processing an
550+
* owned sequence for ALTER TABLE, lock now. Without the lock, we'd
551+
* discard increments from nextval() calls (in other sessions) between
552+
* this function's buffer unlock and this transaction's commit.
553+
*/
554+
LockRelationOid(relid, AccessExclusiveLock);
548555
init_sequence(relid, &elm, &seqrel);
549556

550557
/* check the comment above nextval_internal()'s equivalent call. */

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgrespro/postgres/commit/f88cdb36c457f673a1966a22883ce47e565a37db

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy