Database Reference
In-Depth Information
Removing a user without dropping their data
When trying to drop a user who owns some tables or other database objects, you get the
following error and the user is not dropped:
testdb=# drop user bob;
ERROR: role "bob" cannot be dropped because some objects depend on it
DETAIL: owner of table bobstable
owner of sequence bobstable_id_seq
This recipe presents solutions to this problem.
Getting ready
To modify users, you must either be a superuser or have the CREATEROLE privilege.
How to do it...
The easiest solution to this problem is to not drop the user at all, but just use the trick from a
previous recipe to disallow the user from connecting:
pguser=# alter user bob nologin;
ALTER ROLE
This has the added benefit of having the original owner of the table available later, if needed,
for auditing or debugging purposes ("why is this table here? Who created it?")
How it works...
This turns the user into a role with no login.
You can assign the rights of the "deleted" user to a new user
Use the following code:
pguser=# grant bob bobs_replacement;
GRANT
Assigning ownerships to other users
If you really need to get rid of a user, you have to assign all ownerships to another user, then
run the following query, which is a PostgreSQL extension to SQL standard:
REASSIGN OWNED BY bob TO bobs_replacement;
 
Search WWH ::




Custom Search