REASSIGN_OWNED(7pg14)

πŸ“¦ version 14.24, in opensuse-leap 16.0

πŸ’– 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 to new_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 πŸ‘‘


Later, bestie! πŸ’… This iconic little page is from PostgreSQL 14.24, dated 2026 β€” mwah πŸ«ΆπŸ“

πŸ“¦ where this page comes from