Skip to content

Permission Denied

Error message

                permission denied for table
              

Quick summary

The database user you are connected as does not have the necessary privileges (SELECT, INSERT, UPDATE, DELETE) on the table.

Why this happens

  • The user has not been granted the required privilege

  • You are connected as a user with limited permissions

  • The privilege was revoked

  • The user has privileges on a different database or schema

Minimal example

✗ Broken code
-- User 'reader' tries to insert
INSERT INTO users (name) VALUES ('Ada');
-- → permission denied for table users
✓ Fixed code
-- Grant insert privilege first
GRANT INSERT ON users TO reader;
INSERT INTO users (name) VALUES ('Ada');

The user lacked INSERT permission. Granting it (as a superuser) allows the insert to proceed.

How to diagnose

  • Check the user's privileges: \du username in psql or query the information_schema

  • Verify you are connected as the correct user

  • Check if the privilege is granted on the correct table/schema/database

How to fix

  • Grant the required privilege: GRANT SELECT ON table TO user

  • Connect as a user with sufficient privileges

  • Grant privileges on the schema: GRANT USAGE ON SCHEMA schema TO user

How to prevent

  • Set up roles with appropriate privileges and assign users to roles

  • Document which users need which privileges

  • Use least-privilege principles — grant only what is needed

Related Resources

Related Glossary

Related Lessons

← Back to language