REASSIGN_OWNED(7pg18)
โจ REASSIGN OWNED โจ
ok so bestie, we're in the PostgreSQL 18.6 Documentation and today's main character is REASSIGN_OWNED โ the command that changes the ownership of database objects owned by a database role. it's giving โจhandoverโจ, it's giving ๐passing the aux cord๐, and yes you're gonna want to read this whole thing before you touch anything, fr fr.
๐ธ NAME ๐ธ
REASSIGN_OWNED โ change the ownership of database objects owned by a database role ๐ซถ
โจ 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, politely but with authority, to change the ownership of database objects owned by any of the old_roles to new_role. that's it. that's the whole vibe. ๐
๐ 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. no cap. ๐ฆnew_roleโ the name of the role that will be made the new owner of the affected objects. congrats to them, they're now responsible for everything. ๐
๐ NOTES ๐
ok so listen up because this part matters. ๐ข
REASSIGN OWNED is often used to prepare for the removal of one or more roles. it's literally the "clean out the locker before graduation" command. ๐
โ ๏ธ 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. don't do it once and call it a day, bestie, it's not gonna work like that ๐ญ
REASSIGN OWNED requires membership on both the source role(s) and the target role. so if you don't have both, it's not happening. vibe check failed. ๐
the DROP OWNED command is an alternative that simply drops all the database objects owned by one or more roles. sometimes you don't want to hand stuff over, you just want it gone. different energy entirely. ๐ช๏ธ
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. like, those privileges are not being touched, periodt. ๐
see Section 21.4 for more discussion. ๐
โญ COMPATIBILITY โญ
the REASSIGN OWNED command is a PostgreSQL extension. it's bespoke, it's exclusive, it's an iykyk moment. ๐
๐ SEE ALSO ๐
DROP OWNED(DROP_OWNED(7))DROP ROLE(DROP_ROLE(7))ALTER DATABASE(ALTER_DATABASE(7))
and that's the whole page, bestie!! ๐ฅณ this was PostgreSQL 18.6, dated 2026, and REASSIGN OWNED(7) ate and left no crumbs ๐โจ go forth and reassign responsibly ๐ฆ
๐ฆ where this page comes from
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms