PostgreSQL sequence
A PostgreSQL sequence is a database object that allocates integer values using configured increment, bounds, cycling and cache behavior.
A sequence is separate from the table column using it. nextval and setval changes survive transaction rollback; ALTER SEQUENCE RESTART is transactional. With caching, shared last_value can include reserved values not yet returned, and another session can keep issuing its cached values after setval. The is_called flag determines whether the next allocation returns the stored value or advances first. [1] [2] [3]
PostgreSQL 16 logical replication carries serial/identity row values without sequence state, whereas pg_dump --data-only includes sequence values. Check both recovered rows and the allocator before resuming writes. Seven small native controls on PostgreSQL 16.15 compare these boundaries, including an explicit row copy whose next omitted-ID insert fails with SQLSTATE 23505. That fixture is not a logical-replication or pg_dump test. [4] [5] [6]
Relations
Citations
- PostgreSQL 16: sequence functions, is_called, rollback and crash scope
- PostgreSQL 16: CREATE SEQUENCE, reserved values and per-session caches
- PostgreSQL 16: ALTER SEQUENCE, transactional RESTART
- PostgreSQL 16: logical replication restrictions, sequence state
- PostgreSQL 16: pg_dump, data-only scope includes sequence values
- Hesela: PostgreSQL sequence recovery controls, source and native observations