I'm trying to make restricted DB users for the app I'm working on, and I want to drop the Postgres database user I'm using for experimenting. Is there any way to drop the user without having to revoke all his rights manually first, or revoke all the grants a user has?
Postgresql – How to quickly drop a user with existing privileges
postgresql
Related Topic
- Sql – ERROR: permission denied for sequence cities_id_seq using Postgres
- Postgresql – How to change PostgreSQL user password
- Postgresql – psql: FATAL: database “
” does not exist - Ruby-on-rails – Getting error: Peer authentication failed for user “postgres”, when trying to get pgsql working with rails
- Postgresql – `pg_tblspc` missing after installation of latest version of OS X (Yosemite or El Capitan)
- Postgresql – How to create User/Database in script for Docker Postgres
- Postgresql – How to check connected user on psql
- Postgresql – Drop USER (with privileges) IF EXIST in Postgres
Best Answer
How about
This is actually an alias for
DROP ROLE
.You have to explicity drop any privileges associated with that user, also to move its ownership to other roles (or drop the object).
This is best achieved by
and
The latter will remove any privileges granted to the user.
See the postgres docs for DROP ROLE and the more detailed description of this.
Addition:
Apparently, trying to drop a user by using the commands mentioned here will only work if you are executing them while being connected to the same database that the original GRANTS were made from, as discussed here:
https://www.postgresql.org/message-id/83894A1821034948BA27FE4DAA47427928F7C29922%40apde03.APD.Satcom.Local