postgresql-sequence · shipping

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

related
Logical decoding, Snapshot isolation, Restore test

Citations

  1. PostgreSQL 16: sequence functions, is_called, rollback and crash scope (accessed 2026-10-28)
  2. PostgreSQL 16: CREATE SEQUENCE, reserved values and per-session caches (accessed 2026-10-28)
  3. PostgreSQL 16: ALTER SEQUENCE, transactional RESTART (accessed 2026-10-28)
  4. PostgreSQL 16: logical replication restrictions, sequence state (accessed 2026-10-28)
  5. PostgreSQL 16: pg_dump, data-only scope includes sequence values (accessed 2026-10-28)
  6. Hesela: PostgreSQL sequence recovery controls, source and native observations (accessed 2026-10-28)

Further reading

  1. Hesela: Backup verification and next-write acceptance (accessed 2026-10-28)

JSON: /data/terms/postgresql-sequence.json

Published by Hesela team · Updated

Report a correction · Editorial standards · Reuse guidance

Cite this page
Hesela team. PostgreSQL sequence. Hesela. 2026-10-28. https://hesela.dev/terms/postgresql-sequence/