REASSIGN OWNED is a PostgreSQL utility command that changes the ownership of every object (tables, views, sequences, functions, types, schemas, etc.) currently owned by one or more roles and assigns them to a different role. It is typically used before dropping a role so that dependent objects are not orphaned or accidentally removed. Only superusers or roles with INHERIT privileges on both the source and target roles can execute the command. The statement does not modify privileges granted on those objects; it only alters the owner attribute. For databases with many objects, the operation can take noticeable time because PostgreSQL rewrites catalog entries for each object.
source_role
(name) - One or more existing roles whose objects will be reassigned.target_role
(name) - The role that will become the new owner of the objects.DROP OWNED, ALTER TABLE ... OWNER TO, GRANT, REVOKE, CREATE ROLE, DROP ROLE
PostgreSQL 8.2
It changes the owner of every database object currently owned by one or more roles and assigns those objects to a new role.
Yes. You must be a superuser or have privileges that let you SET ROLE to both the source and target roles; otherwise PostgreSQL raises an error.
No. The command only updates ownership. Existing GRANT or REVOKE permissions stay exactly as they were.
Run the command inside a BEGIN...ROLLBACK block or issue another REASSIGN OWNED that swaps ownership back to the original role.