DROP_OWNED(7pg16)

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

πŸ’… 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 OWNED is often used to prepare for the removal of one or more roles. it's the pre-game, the skincare routine before bed πŸ§–
  • Because DROP OWNED only 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 CASCADE option 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 OWNED command is an alternative that reassigns the ownership of all the database objects owned by one or more roles. However, REASSIGN OWNED does 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 πŸŽ€


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