Postgres:将对未来表的访问权授予各个用户

问题描述 投票:0回答:1

已经有多个主题与此主题相关。但是我无法完成它,并不断出现“权限被拒绝”错误。我一定做错了。

我的目标:在我想要的postgres数据库“ mydatabase”上

  1. 属于角色“ group_x”的大量用户]
  2. 角色“ group_x”的每个成员都应有权访问某个架构“ schema_x”
  3. 在该架构内,所有组成员都应能够创建新表并互相编辑(将来)表。

我如何尝试(大致):

psql -h /var/run/postgresql -p5433 -U postgres

create role group_x;

create role user_a LOGIN INHERIT PASSWORD <password>;
create role user_b LOGIN INHERIT PASSWORD <password>;

grant group_x to user_a;
grant group_x to user_b;

\connect mydatabase;

grant all on schema schema_x to group_x;
grant all on all tables in schema schema_x to group_x;
grant all on all sequences in schema schema_x to group_x;
grant all on all functions in schema schema_x to group_x;

set role group_x;

alter default privileges for role group_x in schema schema_x
    grant all on tables to group_x;
alter default privileges for role group_x in schema schema_x
    grant all on sequences to group_x;
alter default privileges for role group_x in schema schema_x
    grant all on functions to group_x;

感谢您指出我的错误!

database postgresql permissions privileges grant
1个回答
0
投票

如果您是ALTER DEFAULT PRIVILEGES FOR ROLE group_x,则意味着特权仅授予将来的对象由用户group_x创建的对象。

因此您需要在FOR ROLE子句中指定创建表的用户。

© www.soinside.com 2019 - 2024. All rights reserved.