DROP_OWNED(7pg18)
๐ 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 ๐ฅ
REASSIGN OWNED(REASSIGN_OWNED(7))DROP ROLE(DROP_ROLE(7))
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
- 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