Diagnostic Queries
Symptoms
A role lacked the privilege needed to use a sequence (e.g. nextval/currval). PostgreSQL raises SQLSTATE 42501 (insufficient_privilege).
- Missing USAGE/SELECT/UPDATE on the sequence.
- Common when a serial/identity insert needs the sequence.
- Sequence privileges are separate from table privileges.
What the server log shows
ERROR: permission denied for sequence orders_id_seq
Why PostgreSQL raises this — what the manual says
the GRANT reference (Compatibility):
“The sequence privileges SELECT and UPDATE are PostgreSQL extensions.”
Sequence operations require specific privileges (USAGE/SELECT/UPDATE) on the sequence object. Without them — even when inserting into a table whose default uses the sequence — PostgreSQL reports 42501.
Common causes
- The role lacks USAGE/UPDATE on the sequence backing a serial column.
- Granting table privileges but not sequence privileges.
- A new role not covered by default privileges.
How to fix it
- Grant access:
GRANT USAGE ON SEQUENCE orders_id_seq TO app_user;. - Set default privileges so future sequences are usable by the role.
- Prefer identity columns (PG10+) which simplify sequence privileges.
Related & next steps
Reference: PostgreSQL 18 — GRANT.
Thanks — noted. This helps keep the database accurate.