How to fix Permission denied for sequence in PostgreSQL

PostgreSQLINTERMEDIATEMEDIUMUpdated Dec 26, 2025· 396 views

This error occurs when a database user lacks permissions to access a sequence object. Sequences are separate database objects from tables, so granting table permissions does not automatically grant sequence access. The fix involves explicitly granting USAGE and UPDATE privileges on the sequence.

Quick fix

Fixes Permission denied for sequence

psql -U postgres -d your_database_name
  1. Connect to the database as a superuser
  2. Identify the sequence causing the error
  3. Grant USAGE privilege on the specific sequence
  4. Grant permissions on all sequences in a schema at once
postgresql — error
psql -U postgres -d your_database_name
Permission denied for sequence

What this error means

In PostgreSQL, sequences are special single-row table objects that generate unique identifier values. When a table uses a SERIAL column or a DEFAULT nextval() expression, PostgreSQL internally manages a sequence to generate new IDs. This error occurs when a user tries to insert data into a table with an auto-incrementing column but lacks the necessary privileges (USAGE, SELECT, or UPDATE) on the underlying sequence. Unlike table permissions, sequence permissions must be granted separately and explicitly—they are not inherited from table permissions.

Typical symptoms

  • INSERT queries fail with "Permission denied for sequence" error when trying to add rows to tables with SERIAL columns
  • Application cannot insert data into tables with auto-increment IDs even though SELECT and INSERT permissions are granted on the table
  • pg_dump fails with sequence permission errors when backing up the database
  • NEXTVAL() function calls fail with insufficient privilege errors
  • Error messages include the specific sequence name (e.g., "user_id_seq")

Common causes

  1. User does not have USAGE privilege on the sequence object
  2. User does not have UPDATE or SELECT privilege on the sequence needed for nextval() function
  3. Sequence permissions were not granted when the table permissions were configured
  4. SERIAL column was created without properly setting up sequence grants for the application user
  5. Database user was migrated or restored without preserving original sequence permission grants
  6. Azure Database for PostgreSQL user lacks privileges on sequences in shared system schemas

How to fix "Permission denied for sequence"

1Connect to the database as a superuser

Open a terminal and connect to your PostgreSQL database as the postgres superuser:

bash
psql -U postgres -d your_database_name

Or if using a remote connection:

bash
psql -h your_host -U postgres -d your_database_name
2Identify the sequence causing the error

From the error message, note the exact sequence name (e.g., "user_id_seq"). You can also list all sequences in a schema:

sql
\ds public.*

This shows all sequences in the public schema. Replace "public" with your schema name if needed.

3Grant USAGE privilege on the specific sequence

Grant the necessary privileges to your application user. Replace "sequence_name" with your actual sequence name and "app_user" with your database user:

sql
GRANT USAGE, SELECT, UPDATE ON SEQUENCE sequence_name TO app_user;

Breakdown of privileges:
- USAGE: Allows use of currval() and nextval() functions
- SELECT: Allows reading the current sequence value
- UPDATE: Required for nextval() to advance the sequence

4Grant permissions on all sequences in a schema at once

If your application user needs access to multiple sequences, grant permissions on all sequences in a schema in one command:

sql
GRANT USAGE, SELECT, UPDATE ON ALL SEQUENCES IN SCHEMA public TO app_user;

Replace "public" with your actual schema name. This approach is often cleaner than granting on individual sequences.

5Set default sequence permissions for future sequences

To ensure new sequences automatically get the correct permissions, set default privileges:

sql
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT USAGE, SELECT, UPDATE ON SEQUENCES TO app_user;

This ensures any sequences created in the future will have the proper permissions for app_user.

6Verify the fix by testing the operation

Test that the user can now insert data into the affected table:

sql
SET ROLE app_user;
INSERT INTO your_table (name) VALUES ('test');
SET ROLE postgres;

If the INSERT succeeds, permissions are correctly configured. If it still fails, ensure you have granted permissions on all affected sequences.

Advanced notes

By default, PUBLIC has no privileges on sequences in PostgreSQL. When using the azure_pg_admin role in Azure Database for PostgreSQL, ensure your application user has appropriate permissions. If pg_dump fails, it may be dumping system schemas where your user lacks permissions—dump specific schemas instead with the "-n schema_name" flag. In multi-schema applications, remember that each sequence belongs to a specific schema and requires separate grants. The difference between SERIAL (auto-increment) and BIGSERIAL columns does not affect sequence permission requirements—both need explicit grants.

Frequently asked questions

What does "Permission denied for sequence" mean?
In PostgreSQL, sequences are special single-row table objects that generate unique identifier values. When a table uses a SERIAL column or a DEFAULT nextval() expression, PostgreSQL internally manages a sequence to generate new IDs. This error occurs when a user tries to insert data into a table with an auto-incrementing column but lacks the necessary privileges (USAGE, SELECT, or UPDATE) on the underlying sequence.
How do I fix "Permission denied for sequence"?
This error occurs when a database user lacks permissions to access a sequence object. Sequences are separate database objects from tables, so granting table permissions does not automatically grant sequence access. The fix involves explicitly granting USAGE and UPDATE privileges on the sequence.
What causes "Permission denied for sequence"?
User does not have USAGE privilege on the sequence object User does not have UPDATE or SELECT privilege on the sequence needed for nextval() function Sequence permissions were not granted when the table permissions were configured
Is the "Permission denied for sequence" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading