SQLSTATE 42501 ERROR Class 42: Syntax Error or Access Rule Violation

insufficient_privilege must be owner of relation … — 42501

PostgreSQL error "must be owner of relation …" (SQLSTATE 42501): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

Symptoms

A role attempted an operation reserved for the object owner (or a superuser) — such as ALTER, DROP, TRUNCATE, or changing ownership — on a table it does not own. PostgreSQL reports SQLSTATE 42501.

  • DDL like ALTER/DROP fails even when the role can read and write the table.
  • The message names the relation the role must own.
  • Common when application and migration roles differ.

What the server log shows

ERROR:  must be owner of relation orders

Why PostgreSQL raises this — what the manual says

the ALTER TABLE reference (Description):

“You must own the table to use ALTER TABLE.”

Schema-changing commands require ownership rather than a grantable privilege. The catalog records the owner in pg_class.relowner; if the current role is neither the owner (directly or via role membership) nor a superuser, the command is rejected with 42501.

Common causes

  • Migrations run as the application role instead of the owner role.
  • Object owned by a different team/role.
  • Ownership not transferred after a restore or role change.

How to fix it

  1. Run DDL as the owning role, or grant membership: GRANT owner_role TO migration_role;.
  2. Reassign ownership where appropriate: ALTER TABLE orders OWNER TO app_owner;.
  3. Standardize on a single owner role for each schema and run migrations as that role.

Diagnostic query

-- Who owns the relation?
SELECT c.relname, pg_get_userbyid(c.relowner) AS owner
FROM pg_class c WHERE c.relname = 'orders';

Related & next steps

Reference: PostgreSQL 18 — ALTER TABLE.

Was this helpful?