DROP_ROLE(7pg13)

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

πŸ‘‘ DROP_ROLE πŸ’…

okay bestie, so this is the DROP ROLE page from the PostgreSQL 13.23 Documentation (it's a 7pg13 manual page, iykyk) and honestly it's giving "cleanup era" β€” we're about to remove a database role and I'm gonna walk you through it like we're texting at 2am 🫢


✨ SYNOPSIS ✨

DROP ROLE [ IF EXISTS ] name [, ...]

that's it. that's the whole vibe check. slay.


🌸 DESCRIPTION 🌸

DROP ROLE removes the role(s) you specify β€” like, all of them you listed, not just one. icon behavior honestly.

but bestie, there's a guest list check first:

  • to drop a superuser role, you must be a superuser yourself. no cap, no exceptions πŸ’€
  • to drop non-superuser roles, you need the CREATEROLE privilege.

and here's the part where it gets real: a role cannot be removed if it's still referenced in any database of the cluster β€” it will raise an error at you, fr fr. so before you drop the role, you have to:

  • drop all the objects it owns (or reassign their ownership elsewhere), and
  • revoke any privileges the role has been granted on other objects.

the REASSIGN OWNED (REASSIGN_OWNED(7)) and DROP OWNED (DROP_OWNED(7)) commands are literally your besties for this purpose 🫢 β€” see Section 21.4 for more discussion if you want the deep lore.

however (and this is the good news 🌈): you do not need to remove role memberships involving the role. DROP ROLE automatically revokes any memberships of the target role in other roles, and of other roles in the target role. the other roles are not dropped, nor otherwise affected. they're fine. they're thriving. main character energy preserved πŸ‘‘


πŸŽ€ PARAMETERS πŸŽ€

  • IF EXISTS β€” do not throw an error if the role does not exist. a notice is issued in this case instead. so polite of it honestly πŸŽ€
  • name β€” the name of the role to remove. that's the placeholder bestie, you put the actual name there πŸ’…

πŸ¦‹ NOTES πŸ¦‹

PostgreSQL includes a program dropuser(1) that has the same functionality as this command β€” in fact, it literally calls this command πŸ™ˆ β€” but it can be run from the command shell. so like, if you're a terminal girly, that one's for you.


⭐ EXAMPLES ⭐

to drop a role:

DROP ROLE jonathan;

bye jonathan πŸ‘‹βœ¨ (affectionate)


πŸ’œ COMPATIBILITY πŸ’œ

the SQL standard defines DROP ROLE, but it only allows one role to be dropped at a time, and it specifies different privilege requirements than PostgreSQL uses. so like... we're built different. periodt.


πŸ”₯ SEE ALSO πŸ”₯

the whole role cinematic universe honestly 🌈


okay that's the page!! brought to you by PostgreSQL 13.23, dated 2025 β€” mwah, go drop those roles responsibly bestie πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from