PostgreSQL drop role fails because of default privileges

青春壹個敷衍的年華 提交于 2019-12-05 12:12:01

问题


I am trying to drop a role 'xyz' that was previously the owner of the schema with the same name 'xyz'. I altered the schema ownership as below, and run reassigned ownership just in case (although all tables were created by a different user with superuser power). So I run all these:

alter schema xyz owner to postgres;
reassign owned by xyz to postgres;
alter default privileges in schema seeds revoke all on tables from xyz cascade;
alter default privileges in schema seeds revoke all on sequences from xyz cascade;
alter default privileges in schema seeds revoke all on functions from xyz cascade;

And still getting the error:

drop role xyz;
ERROR:  role "xyz" cannot be dropped because some objects depend on it
DETAIL:  owner of default privileges on new relations belonging to role xyz in schema xyz

Also FYI:

postgres=# \du rsi
List of roles
Role name |   Attributes   | Member of   
-----------+----------------+-----------
rsi       | No inheritance | {}

What am I missing? Any help would be appreciated! Thanks!!


回答1:


Taken from the PostgreSQL documentation on ALTER DEFAULT PRIVILEGES, Notes section:

If you wish to drop a role for which the default privileges have been altered, it is necessary to reverse the changes in its default privileges or use DROP OWNED BY to get rid of the default privileges entry for the role.

Another worthy mention from the documentation regarding DROP OWNED BY in this case is also that

Because DROP OWNED only affects the objects in the current database, it is usually necessary to execute this command in each database that contains objects owned by a role that is to be removed.

Therefore, your mileage may vary, meaning that you may have to issue the statement in more DBs.

Having received the same messages as mentioned in the question, I've tried out the DROP OWNED BY statement and it worked. Hope this helps!




回答2:


First run command :

DROP OWNED BY xyz;

then:

DROP ROLE xyz;

Read PostgreSQL Documentation regarding Drop Owned By.



来源:https://stackoverflow.com/questions/9840955/postgresql-drop-role-fails-because-of-default-privileges

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!