【问题标题】:PostgreSQL drop role fails because of default privilegesPostgreSQL 删除角色因默认权限而失败
【发布时间】:2012-04-08 02:47:58
【问题描述】:

我正在尝试删除角色“xyz”,该角色以前是具有相同名称“xyz”的架构所有者。我如下更改了架构所有权,并运行重新分配的所有权以防万一(尽管所有表都是由具有超级用户权限的不同用户创建的)。所以我运行所有这些:

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;

仍然出现错误:

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

也仅供参考:

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

我错过了什么?任何帮助,将不胜感激!谢谢!!

【问题讨论】:

  • 将其移至 dba.stackexchange.com ?

标签: postgresql sql-drop


【解决方案1】:

首次运行命令:

DROP OWNED BY xyz;

然后:

DROP ROLE xyz;

阅读有关 Drop Owned By 的 PostgreSQL 文档。

【讨论】:

    【解决方案2】:

    取自PostgreSQL documentationALTER DEFAULT PRIVILEGES,备注部分:

    如果您希望删除已更改默认权限的角色,则需要反转其默认权限中的更改或使用 DROP OWNED BY 删除该角色的默认权限条目。

    在这种情况下,关于DROP OWNED BY 的文档中的另一个worthy mention 也是

    因为 DROP OWNED 只影响当前数据库中的对象,所以通常需要在每个包含要删除的角色拥有的对象的数据库中执行此命令。

    因此,您的里程可能会有所不同,这意味着您可能需要在更多的数据库中发出声明。

    收到与问题中提到的相同的消息后,我尝试了DROP OWNED BY 语句并且它有效。希望这会有所帮助!

    【讨论】:

    • DROP OWNED BY usr; 后跟 DROP USER usr; 为我工作,谢谢!
    猜你喜欢
    • 2019-06-02
    • 2014-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-14
    • 1970-01-01
    相关资源
    最近更新 更多