REASSIGN_OWNED(7pg14)
π NAME π
REASSIGN OWNED(7) β okay so this one changes the ownership of database objects owned by a database role. Bestie, it's literally a glow-up for object ownership. π
β¨ SYNOPSIS β¨
REASSIGN OWNED BY { old_role | CURRENT_ROLE | CURRENT_USER | SESSION_USER } [, ...]
TO { new_role | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
π¦ DESCRIPTION π¦
REASSIGN OWNED tells the system to change the ownership of database objects owned by any of the old_roles to new_role. That's the whole vibe: old owner out, new owner in, database objects get reassigned. β¨
πΈ PARAMETERS πΈ
old_roleβ the name of a role. The ownership of all the objects within the current database, and of all shared objects (databases, tablespaces), owned by this role will be reassigned tonew_role. πnew_roleβ the name of the role that will be made the new owner of the affected objects. Main character energy fr fr. π
π NOTES π
REASSIGN OWNED is often used to prepare for the removal of one or more roles. Like, you're clearing the way before a role exits the group chat. π
Because REASSIGN OWNED does not affect objects within other databases, it is usually necessary to execute this command in each database that contains objects owned by a role that is to be removed. So yes, bestie, you may need to run it in every relevant database β no skipping around. π«Ά
β οΈ Heads up: REASSIGN OWNED requires membership on both the source role(s) and the target role.
The DROP OWNED command is an alternative that simply drops all the database objects owned by one or more roles. Different vibe, same cleanup friend group. π
The REASSIGN OWNED command does not affect any privileges granted to the old_roles on objects that are not owned by them. Likewise, it does not affect default privileges created with ALTER DEFAULT PRIVILEGES. Use DROP OWNED to revoke such privileges. This part is lowkey important β don't assume reassigning ownership handles every privilege. π
See Section 22.4 for more discussion. π
π COMPATIBILITY π
The REASSIGN OWNED command is a PostgreSQL extension. It's giving PostgreSQL-specific, iykyk. πβ¨
π SEE ALSO π
DROP OWNED(DROP_OWNED(7))DROP ROLE(DROP_ROLE(7))ALTER DATABASE(ALTER_DATABASE(7))
Later, bestie! π This iconic little page is from PostgreSQL 14.24, dated 2026 β mwah π«Άπ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms