Coding⏱️ 3 min read📅 2026-06-03

How to Fix: ERROR: permission denied for sequence cities_id_seq using Postgres

SQL permission denied error due to incorrect sequence grant.

Quick Answer: The issue is caused by the incorrect spelling of 'cities_id_seq' in the last grant statement. Change 'ci' to 'cities_id_seq'.

The ERROR: permission denied for sequence cities_id_seq using Postgres error occurs when the PostgreSQL database is unable to grant permissions to access the 'cities_id_seq' sequence created by the SQL script. This issue affects users who have been granted select, insert, or delete privileges on the 'cities' table but do not have sufficient permissions to access the sequence.

This error can be frustrating as it prevents the user from performing certain operations, such as inserting new data into the 'cities' table. However, by following the steps outlined in this guide, you should be able to resolve the issue and regain access to the 'cities_id_seq' sequence.

💡 Why You Are Getting This Error

  • The primary reason for this error is that the PostgreSQL database does not recognize the user who has been granted privileges on the 'cities' table. This can occur if the user's password or username is incorrect, or if the user's account has not been properly created in the PostgreSQL database.
  • Another possible cause of this error is that the SQL script was executed incorrectly, resulting in the creation of an invalid sequence. In this case, the 'cities_id_seq' sequence may not exist in the PostgreSQL database, causing the permission denied error.

🛠️ Step-by-Step Verified Fixes

Recreate the Sequence

  1. Step 1: Open a terminal or command prompt and navigate to the directory where your PostgreSQL database is located.
  2. Step 2: Type the following command to recreate the 'cities_id_seq' sequence: `CREATE SEQUENCE cities_id_seq;` This will create a new sequence with the same name as the original sequence, but without any permissions issues.
  3. Step 3: Once the sequence has been recreated, try running the SQL script again. If the error persists, proceed to method 2.

Recreate the Table and Sequence

  1. Step 1: Drop the 'cities' table by typing the following command: `DROP TABLE cities;` This will remove the table from the PostgreSQL database, which should resolve any permissions issues.
  2. Step 2: Recreate the 'cities' table using the original SQL script. Once the table has been recreated, try running the SQL script again.

💡 Conclusion

To summarize, the ERROR: permission denied for sequence cities_id_seq using Postgres error can be resolved by recreating the 'cities_id_seq' sequence or dropping and re-creating the 'cities' table. If you are still experiencing issues after following these steps, please consult the PostgreSQL documentation for further assistance.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions