DROP_OWNED(7pg18)

๐Ÿ“ฆ version 18.6, in opensuse-leap 16.0

๐Ÿ’… DROP OWNED โ€” ok bestie let's clean house

so this is the DROP OWNED page from the PostgreSQL 18.6 Documentation, manual section 7, and it's literally about removing database objects owned by a database role. no cap. ๐ŸŽ€


โœจ NAME โœจ

DROP OWNED โ€” remove database objects owned by a database role ๐Ÿงน๐Ÿ’–


๐ŸŒธ SYNOPSIS ๐ŸŒธ

DROP OWNED BY { name | CURRENT_ROLE | CURRENT_USER | SESSION_USER } [, ...] [ CASCADE | RESTRICT ]

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

okay so here's the tea ๐Ÿ“ โ€” DROP OWNED drops all the objects within the current database that are owned by one of the specified roles. all of them. every last one. she's thorough like that. ๐Ÿ’…

and it doesn't stop there, bestie. any privileges granted to the given roles on objects in the current database โ€” or on shared objects (databases, tablespaces, configuration parameters) โ€” will also be revoked. privileges? gone. objects? gone. it's giving spring cleaning but make it SQL. โœจ


๐ŸŽ€ PARAMETERS ๐ŸŽ€

  • name โ€” the name of a role whose objects will be dropped, and whose privileges will be revoked. that's your target, bestie. ๐ŸŽฏ
  • CASCADE โ€” automatically drop objects that depend on the affected objects, and in turn all objects that depend on those objects (see Section 5.15). it's a chain reaction, lowkey. ๐ŸŒ€
  • RESTRICT โ€” refuse to drop the objects owned by a role if any other database objects depend on one of the affected objects. this one is the default, so if you don't say anything, this is the energy you get. she's cautious. she's sensible. ๐Ÿซถ

๐Ÿ‘‘ NOTES ๐Ÿ‘‘

okay so the classic move โ€” DROP OWNED is often used to prepare for the removal of one or more roles. you gotta clear the decks before you yeet the role. ๐Ÿงš

but here's the catch, and it's important fr fr: because DROP OWNED only affects the objects in the current database, it's usually necessary to execute this command in each database that contains objects owned by a role that is to be removed. every. single. one. she's per-database, she said what she said. ๐Ÿ˜ญ

โš ๏ธ using the CASCADE option might make the command recurse to objects owned by other users. not just your role. other users. just so you know. ๐Ÿ’€

the REASSIGN OWNED command is an alternative that reassigns the ownership of all the database objects owned by one or more roles. however โ€” and this is the plot twist โ€” REASSIGN OWNED does not deal with privileges for other objects. ๐Ÿ™ˆ

databases and tablespaces owned by the role(s) will not be removed. nope. those stay. ๐ŸŒˆ

see Section 21.4 for more discussion. iykyk. โญ


๐Ÿ’œ COMPATIBILITY ๐Ÿ’œ

the DROP OWNED command is a PostgreSQL extension. she's homegrown. she's ours. periodt. ๐Ÿ‘‘


๐Ÿ”ฅ SEE ALSO ๐Ÿ”ฅ


and that's the whole page bestie!! ๐Ÿซถ this was PostgreSQL 18.6, dated 2026, and honestly? iconic. go forth and drop responsibly. ๐Ÿ’–โœจ๐ŸŽ€๐Ÿฆ‹๐ŸŒธ

๐Ÿ“ฆ where this page comes from