ERROR: must be owner of table (PostgreSQL) — how to fix
ERROR: must be owner of table users
ERROR: must be owner of relation users
Quick fix: Run the statement as the table owner, or have the owner/superuser transfer it: ALTER TABLE users OWNER TO app_user;. For a whole schema use REASSIGN OWNED BY old_role TO app_user;. Or grant the owning role to your user: GRANT old_role TO app_user;.
What it means
In PostgreSQL every table, sequence, view and function has an owner role. Some operations are reserved for the owner and cannot be granted with GRANT, including:
ALTER TABLE(add/drop columns, add constraints, rename)DROP TABLECREATE INDEXon the tableCOMMENT ON TABLE,ALTER TABLE ... OWNER TO
So even GRANT ALL PRIVILEGES ON users TO app_user is not enough to run a migration that alters users. This is the classic situation where tables were created by postgres (e.g. restored from a dump) and the app's migration user later tries to change them.
Find the current owner:
SELECT tablename, tableowner FROM pg_tables WHERE tablename = 'users';
or \dt users in psql.
Fix 1: transfer ownership to the role that runs migrations
Connect as the current owner or a superuser:
ALTER TABLE users OWNER TO app_user;
Remember related objects: sequences (ALTER SEQUENCE users_id_seq OWNER TO app_user;), views and functions have their own owners. A sequence owned by a column (serial/identity) follows its table when the table's owner changes.
Fix 2: transfer everything owned by a role
To move all objects that postgres (or an old role) owns in the current database:
REASSIGN OWNED BY old_owner TO app_user;
Run it in each database concerned. Be careful with REASSIGN OWNED BY postgres: it also reassigns other objects owned by postgres in that database, and it fails for objects required by the system. In that case, change owners per table with a loop:
DO $$
DECLARE r record;
BEGIN
FOR r IN SELECT tablename FROM pg_tables WHERE schemaname = 'public' LOOP
EXECUTE format('ALTER TABLE public.%I OWNER TO app_user', r.tablename);
END LOOP;
END $$;
Fix 3: make the user a member of the owning role
Members of the owning role can act as owner. Useful when several users should manage the same tables:
CREATE ROLE app_owner NOLOGIN;
ALTER TABLE users OWNER TO app_owner;
GRANT app_owner TO app_user, migrator;
If the role was created with NOINHERIT, the member must run SET ROLE app_owner; first.
Fix 4: restore dumps without the original owners
When restoring a dump made on another server, skip ownership so all objects belong to the restoring user:
pg_restore --no-owner --role=app_user -d mydb dump.backup
For a plain SQL dump, create it with pg_dump --no-owner and run it as app_user.
Fix 5: managed databases (RDS, Cloud SQL, Azure)
The admin user on managed services is not a true superuser. It can still run ALTER TABLE ... OWNER TO if it is a member of both the current owner role and the new owner role, so grant those memberships first:
GRANT old_owner TO admin_user;
GRANT app_user TO admin_user;
ALTER TABLE users OWNER TO app_user;
Last updated 2026-12-02.