PostgreSQL – ERROR: permission denied for relation

You might encounter the below error while accessing a database object in Postgres database.

Error : permission denied for relation <your_object_name>

The issue here is that you do not have privileges granted on the database object <your_object_name> to your user account.

You should grant the required privileges on the database object to the user to resolve the error.

If your database object is a table, and the user is trying to select from the table, run the below grant statement(as a super user or schema owner):

grant select on <your_table_name> to <username>;

You can also grant insert, update, delete or ALL privileges on the table to the user/group as required. It is a best practice to always grant minimum required privileges on the database objects to users.

If your database object is a function, run the below grant statement:

grant execute on function func_name(a integer, b varchar) to <username>;
See also  PostgreSQL - SELECT Statement