Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f88cdb3

Browse filesBrowse 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
Copy full SHA for f88cdb3

File tree

Expand file treeCollapse file tree

1 file changed

+7
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+7
-0
lines changed

‎src/backend/commands/sequence.c

Copy file name to clipboardExpand all lines: src/backend/commands/sequence.c
+7Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.