DROP_OWNED(7pg16)
π DROP OWNED (7pg16) β like, the whole glow-up
okay bestie, so this is the page for DROP OWNED in the PostgreSQL 16 docs, and honestly? It's giving "cleanup era." Let me walk you through it π§Ήβ¨
β¨ NAME β¨
DROP_OWNED β yeet every database object that a database role owns. literally the "delete their whole closet" command π
πΈ SYNOPSIS πΈ
DROP OWNED BY { name | CURRENT_ROLE | CURRENT_USER | SESSION_USER } [, ...] [ CASCADE | RESTRICT ]
bestie you can list multiple roles, comma-separated. Periodt.
π DESCRIPTION π
So DROP OWNED drops all the objects within the current database that are owned by one of the roles you name. π«Ά
And that's not all β any privileges granted to those roles on objects in the current database, or on shared objects (databases, tablespaces, configuration parameters) get revoked too. so it's drops and revokes, a whole two-for-one π₯
heads up: "current database" is doing a LOT of heavy lifting in that sentence. we'll get to it in NOTES, don't worry π
π¦ PARAMETERS π¦
nameβ the name of a role whose objects will be dropped, and whose privileges will be revoked. yeah, that's the whole vibe πCASCADEβ automatically drop objects that depend on the affected objects, and in turn all objects that depend on those objects (see Section 5.14). it's the "and everyone they brought to the party" option πRESTRICTβ refuse to drop the objects owned by a role if any other database objects depend on one of the affected objects. This is the default. she's cautious, she's sensible, she's the group chat mom π
π NOTES π
DROP OWNEDis often used to prepare for the removal of one or more roles. it's the pre-game, the skincare routine before bed π§- Because
DROP OWNEDonly affects the objects in the current database, it is usually necessary to execute this command in each database that contains objects owned by a role that is to be removed. no cap β this is the #1 gotcha. one database at a time, bestie π - Using the
CASCADEoption might make the command recurse to objects owned by other users. so like... it can wander into someone else's closet. be aware π - The
REASSIGN OWNEDcommand is an alternative that reassigns the ownership of all the database objects owned by one or more roles. However,REASSIGN OWNEDdoes not deal with privileges for other objects. so it's not a 1:1 swap, iykyk β¨ - Databases and tablespaces owned by the role(s) will not be removed. they survive. main character energy, they simply cannot be dropped by this command π
- See Section 22.4 for more discussion. go read it, it's tea β
π COMPATIBILITY π
The DROP OWNED command is a PostgreSQL extension. it's homegrown, not standard SQL, and we love that for it π
π SEE ALSO π
REASSIGN OWNED(REASSIGN_OWNED(7))DROP ROLE(DROP_ROLE(7))
okay that's the whole page, you ate that π mwah π
π« sign-off tingz: this iconic piece of documentation comes to you from PostgreSQL 16.15, dated 2026, and it's filed under DROP OWNED(7). stan. β
π¦ where this page comes from
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms