Search code examples
postgresqldatabase-permissions

Permission denied on schema in PostgreSQL


I can't find why I am getting an permission denied error in my database.

The role owns the schema and has access to the table, but still the log says:

ERROR: permission denied for schema myschema at character 20
QUERY: SELECT 1 FROM ONLY "myshema"."mytable" x WHERE "id" OPERATOR(pg_catalog.=) $1 FOR KEY SHARE OF x

Solution

  • There is a foreign key in a table referring to a table in the schema in question, to which the table owner role does not have access granted. Foreign key checks are done with the permissions of the role that owns the table, not the role performing the query.

    The query is actually doing the internal foreign key check.