index 28f85222647b067ecaab015bbf5bfb533843677d..b4ad19c05396062e2b99861d23be77ee0ec9c5e6 100644 (file)
@@ -545,6 +545,13 @@ SequenceChangePersistence(Oid relid, char newrelpersistence)
Buffer buf;
HeapTupleData seqdatatuple;
+ /*
+ * ALTER SEQUENCE acquires this lock earlier. If we're processing an
+ * owned sequence for ALTER TABLE, lock now. Without the lock, we'd
+ * discard increments from nextval() calls (in other sessions) between
+ * this function's buffer unlock and this transaction's commit.
+ */
+ LockRelationOid(relid, AccessExclusiveLock);
init_sequence(relid, &elm, &seqrel);
/* check the comment above nextval_internal()'s equivalent call. */