DROP_ROLE(7pg18)

๐Ÿ“ฆ version 18.6, in opensuse-leap 16.0

๐Ÿ’… DROP ROLE โ€” the "okay bestie, we're deleting a whole role" page

PostgreSQL 18.6 Documentation ๐ŸŽ€ (yes, this is the DROP ROLE(7) page, and yes it's lowkey iconic)


โœจ NAME โœจ

DROP_ROLE โ€” remove a database role ๐Ÿซถ


๐ŸŒธ SYNOPSIS ๐ŸŒธ

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

๐Ÿ’– DESCRIPTION ๐Ÿ’–

Okay so. DROP ROLE removes the role(s) you name. That's it, that's the whole vibe. โœจ

But bestie, there's a permissions check first, and it's giving โœ‹:

  • Wanna drop a superuser role? Then you have to be a superuser yourself. No exceptions, no cap. ๐Ÿ‘‘
  • Dropping non-superuser roles? Cool, but you need the CREATEROLE privilege and you must have been granted ADMIN OPTION on the role in question. Both. Not one. Both. ๐Ÿ’…

Now here's the part that gets people ๐Ÿ˜ญ โ€” a role cannot be removed if it's still referenced anywhere in any database of the cluster. If it is, an error gets raised, periodt.

So before you drop it, you gotta:

  • 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 can be useful for this purpose โ€” go check out Section 21.4 for more discussion on that.

BUT ๐ŸŒˆ here's the good news, the plot twist, the moment: 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. The other roles aren't dropped, aren't touched, aren't affected. They're fine. They're thriving. ๐Ÿฆ‹


๐ŸŽ€ PARAMETERS ๐ŸŽ€

  • IF EXISTS โ€” don't throw an error if the role doesn't exist. In that case, a notice is issued instead. Chill behaviour honestly. ๐ŸŒธ
  • name โ€” the name of the role to remove. Say it with your chest. ๐Ÿ’…

โญ NOTES โญ

PostgreSQL ships a program called dropuser(1) that has the exact same functionality as this command โ€” in fact, it literally calls this command โ€” but it can be run from the command shell. So if you live in a terminal all day (iykyk), that's your girl. ๐Ÿงš


๐Ÿ”ฅ EXAMPLES ๐Ÿ”ฅ

To drop a role:

DROP ROLE jonathan;

And that's it. Jonathan is gone. Gone gone. ๐Ÿ’€ (respectfully ๐Ÿ™ˆ)


๐Ÿ’œ COMPATIBILITY ๐Ÿ’œ

The SQL standard does define DROP ROLE, so like, we're not out here making things up. BUT โ€” the standard only allows one role to be dropped at a time, and it specifies different privilege requirements than PostgreSQL uses. So don't expect the standard's rules to match ours, bestie. ๐ŸŒˆ


๐Ÿซถ SEE ALSO ๐Ÿซถ


PostgreSQL 18.6 ยท 2026 ยท DROP ROLE(7) โ€” mwah, that's the whole page, thanks for reading, go drop your roles responsibly ๐Ÿ’–โœจ๐ŸŽ€

๐Ÿ“ฆ where this page comes from