如果它具有依赖对象,如何将用户放入 postgres
How to drop user in postgres if it has depending objects
数据库 idd 所有者是角色 idd_owner
。
数据库有 2 个数据模式:public
和 firma1
。
用户可能在此数据库和对象中直接或间接分配了权限。
用户不是任何对象的所有者。它只授予了权利。
如何删除这样的用户?
我试过了
revoke all on all tables in schema public,firma1 from "vantaa" cascade;
revoke all on all sequences in schema public,firma1 from "vantaa" cascade;
revoke all on database idd from "vantaa" cascade;
revoke all on all functions in schema public,firma1 from "vantaa" cascade;
revoke all on schema public,firma1 from "vantaa" cascade;
revoke idd_owner from "vantaa" cascade;
ALTER DEFAULT PRIVILEGES IN SCHEMA public,firma1 revoke all ON TABLES from "vantaa";
DROP ROLE if exists "vantaa"
但出现错误
role "vantaa" cannot be dropped because some objects depend on it
DETAIL: privileges for schema public
DROP ROLE if exists "vantaa"
如何解决此问题以便用户可以删除?
如何创建 sql 或 plpgsql 方法以用户名作为参数并在所有情况下删除该用户而不删除数据?
使用 Postgres 9.1+
在删除用户之前,您可以 运行 :
REASSIGN OWNED BY vantaa TO <newuser>
如果您不知道将其重新分配给谁,您可以重新分配给 postgres ...
REASSIGN OWNED BY vantaa TO postgres;
您的重新分配可能会失败。
当您重新分配给新的 user/role
- 你在当前选择的数据库上做
- 当前用户必须属于 'from' 角色和 'to'(授予它们并在之后撤销它们)
我的 shell 脚本摘录(省略了一些内容)
# The DROP USER operation will fail if this user is the owner of an existing schema, table, index...
# The user creating a resource owns it. It should transfer the ownership to the role
# When reassigning, the current user needs to have the <<roles>> associated to BY and TO to execute the command.
GRANT $_roleservice TO $_superuser;
GRANT $_account TO $_superuser;
REASSIGN OWNED BY $_account TO $_roleservice;
# dropping the user removes it from the current user list of roles/users
DROP USER $_account;
REVOKE $_roleservice FROM $_superuser;
数据库 idd 所有者是角色 idd_owner
。
数据库有 2 个数据模式:public
和 firma1
。
用户可能在此数据库和对象中直接或间接分配了权限。
用户不是任何对象的所有者。它只授予了权利。
如何删除这样的用户?
我试过了
revoke all on all tables in schema public,firma1 from "vantaa" cascade;
revoke all on all sequences in schema public,firma1 from "vantaa" cascade;
revoke all on database idd from "vantaa" cascade;
revoke all on all functions in schema public,firma1 from "vantaa" cascade;
revoke all on schema public,firma1 from "vantaa" cascade;
revoke idd_owner from "vantaa" cascade;
ALTER DEFAULT PRIVILEGES IN SCHEMA public,firma1 revoke all ON TABLES from "vantaa";
DROP ROLE if exists "vantaa"
但出现错误
role "vantaa" cannot be dropped because some objects depend on it
DETAIL: privileges for schema public
DROP ROLE if exists "vantaa"
如何解决此问题以便用户可以删除?
如何创建 sql 或 plpgsql 方法以用户名作为参数并在所有情况下删除该用户而不删除数据?
使用 Postgres 9.1+
在删除用户之前,您可以 运行 :
REASSIGN OWNED BY vantaa TO <newuser>
如果您不知道将其重新分配给谁,您可以重新分配给 postgres ...
REASSIGN OWNED BY vantaa TO postgres;
您的重新分配可能会失败。 当您重新分配给新的 user/role - 你在当前选择的数据库上做 - 当前用户必须属于 'from' 角色和 'to'(授予它们并在之后撤销它们)
我的 shell 脚本摘录(省略了一些内容)
# The DROP USER operation will fail if this user is the owner of an existing schema, table, index...
# The user creating a resource owns it. It should transfer the ownership to the role
# When reassigning, the current user needs to have the <<roles>> associated to BY and TO to execute the command.
GRANT $_roleservice TO $_superuser;
GRANT $_account TO $_superuser;
REASSIGN OWNED BY $_account TO $_roleservice;
# dropping the user removes it from the current user list of roles/users
DROP USER $_account;
REVOKE $_roleservice FROM $_superuser;