REASSIGN_OWNED(7)

โœจ 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 to new_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 ๐Ÿฆ‹