gpt4 book ai didi

sql - 无法删除 PostgreSQL 角色。错误 : `cannot be dropped because some objects depend on it`

转载 作者:行者123 更新时间:2023-11-29 11:14:34 27 4
gpt4 key购买 nike

我试图删除 PostgreSQL 用户:

DROP USER ryan;

我收到这个错误:

Error in query:
ERROR: role "ryan" cannot be dropped because some objects depend on it
DETAIL: privileges for database mydatabase

我从这些线程中寻找解决方案:

还是一样的错误

这发生在我授予用户“ryan”所有权限后:

GRANT ALL PRIVILEGES ON DATABASE mydatabase ON SCHEMA public TO ryan;

最佳答案

DROP USER (或 DROP ROLE,同样的事情)当角色仍然拥有任何东西或对其他对象具有任何授予的特权时无法继续。

使用DROP OWNED 摆脱所有特权(从措辞上看不太明显)The manual:

[...] Any privileges granted to the given roles on objects in the currentdatabase and on shared objects (databases, tablespaces) will also be revoked.

因此删除角色的可靠命令顺序是:

REASSIGN OWNED BY ryan TO postgres;  -- or some other trusted role
DROP OWNED BY ryan;

在角色拥有任何东西或拥有任何特权的同一集群的每个数据库中运行这两个命令!
最后:

DROP USER ryan;
  • REASSIGN OWNED更改角色当前拥有的所有对象的所有权。
  • DROP OWNED然后只撤销特权(不妨碍所有权)。

或者,您可以跳过 REASSIGN OWNED。然后 DROP OWNED 将(也)删除用户拥有的所有对象。 (你确定吗?!)

相关:

关于sql - 无法删除 PostgreSQL 角色。错误 : `cannot be dropped because some objects depend on it` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51256454/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com