DROP_ROLE(7pg17)
π 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
CREATEROLEprivilege and you must have been grantedADMIN OPTIONon 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 π
CREATE ROLE(CREATE_ROLE(7))ALTER ROLE(ALTER_ROLE(7))SET ROLE(SET_ROLE(7))
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
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-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