无法删除PostgreSQL角色。错误:由于某些对象依赖它,因此无法删除` [英] Cannot drop PostgreSQL role. Error: `cannot be dropped because some objects depend on it`
本文介绍了无法删除PostgreSQL角色。错误:由于某些对象依赖它,因此无法删除`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正试图删除PostgreSQL用户:
I was trying to delete PostgreSQL user:
DROP USER ryan;
我收到此错误:
Error in query:
ERROR: role "ryan" cannot be dropped because some objects depend on it
DETAIL: privileges for database mydatabase
我从这些线程中寻找解决方案:
I looked for a solution from these threads:
- PostgreSQL - how to quickly drop a user with existing privileges
- How to drop user in postgres if it has depending objects
仍然有相同的错误。
这种情况发生在我向用户 ryan授予所有权限后:
This happens after I grant all permission to user "ryan" with:
GRANT ALL PRIVILEGES ON DATABASE mydatabase ON SCHEMA public TO ryan;
推荐答案
使用 <$摆脱所有特权c $ c> DROP OWNED (在措辞上不太明显)。 手册:
[...]在当前
数据库中的对象和共享对象(数据库,表空间)上授予给定角色的任何特权也将被撤销。
[...] Any privileges granted to the given roles on objects in the current database and on shared objects (databases, tablespaces) will also be revoked.
因此删除角色的可靠命令顺序为:
So the reliable sequence of commands to drop a role is:
REASSIGN OWNED BY ryan TO postgres; -- or some other trusted role
DROP OWNED BY ryan;
-- repeat in ALL databases where the role owns anything or has any privileges!
DROP USER ryan;
相关:
- 使用特权丢弃角色 (使用函数来为所有相关的数据库生成命令)
- 查找链接到PostgreSQL角色的对象
- Drop a role with privileges (with a function to generate commands for all relevant DBs)
- Find objects linked to a PostgreSQL role
这篇关于无法删除PostgreSQL角色。错误:由于某些对象依赖它,因此无法删除`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文