Skip to content

LOCK SEQUENCE

Lock a sequence within a transaction so that other users and sessions cannot modify the sequence until the locking transaction ends or is rolled back.

LOCK SEQUENCE name

This command must be run within a transaction block. For example:

premdb_session1=# begin;
BEGIN
premdb_session1=# lock sequence matchkey;
LOCK
premdb_session1=# ...

Another session's attempt to set a new start value for this sequence has to wait until this transaction commits or rolls back:

premdb_session2=# alter sequence matchid start 5000000;
...
<locking transaction ends>
ALTER SEQUENCE

Parent topic:SQL Commands