DROP_ROLE(7pg17)

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

πŸ’… DROP ROLE (7pg17) β€” the "so you wanna delete a role" page

okay bestie, welcome to the PostgreSQL 17.11 docs, page DROP ROLE(7) ✨ this is where you learn how to yeet a database role into the sun. let's get into it 🫢


🌸 NAME 🌸

DROP_ROLE β€” remove a database role, periodt. that's the whole vibe πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

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

✨ DESCRIPTION ✨

okay so DROP ROLE removes the role(s) you name β€” and yeah, you can do multiple at once, we love efficiency πŸ’–

but here's the gatekeeping, and ngl it's real:

  • wanna drop a superuser role? you gotta be a superuser yourself. no shortcuts 🚫
  • wanna drop non-superuser roles? you need the CREATEROLE privilege and you must have been granted ADMIN OPTION on that role. both. not one. both πŸ’€

also, a role literally cannot be removed if it's still referenced anywhere in any database of the cluster β€” you'll get an error, no cap 😭. so before you drop it, you must:

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

the REASSIGN OWNED and DROP OWNED commands are your besties for this exact purpose 🫢 β€” see Section 21.4 for more discussion on that.

BUT β€” and this is the good news β€” you do not need to go 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. iconic, honestly πŸ‘‘. the other roles are not dropped nor otherwise affected β€” they're fine, they're thriving, they're not even thinking about it 🌈


πŸŽ€ PARAMETERS πŸŽ€

  • IF EXISTS β€” don't throw an error if the role doesn't exist. a notice gets issued in this case instead. it's giving "gentle letdown" πŸ’œ
  • name β€” the name of the role to remove. that's it. that's the parameter πŸ“

⭐ NOTES ⭐

PostgreSQL ships with a program called 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 if you're a shell girlie, that's your moment 🐚✨


πŸ”₯ EXAMPLES πŸ”₯

to drop a role:

DROP ROLE jonathan;

and jonathan is gone. bye jonathan πŸ‘‹πŸ’€


🌈 COMPATIBILITY 🌈

the SQL standard does define DROP ROLE, so points for existing β€” but it only allows one role to be dropped at a time, and it specifies different privilege requirements than PostgreSQL uses. so like... related, but not the same energy πŸ™ˆ


πŸ‘‘ SEE ALSO πŸ‘‘


okay that's the whole page, you're officially a role-dropping icon now πŸ§šπŸ’– this has been PostgreSQL 17.11, dated 2026, signing off as DROP ROLE(7) β€” go forth and drop responsibly, bestie 🫢🌸

πŸ“¦ where this page comes from