Postgres:向各种用户授予对将来表的访问权限

时间:2020-02-04 17:11:56

标签: database postgresql permissions privileges grant

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

我的目标:在我想要的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;

感谢您指出我的错误!

1 个答案:

答案 0 :(得分:0)

如果您MyList <- list(data1,data2,data3...,data12) ,则意味着特权仅授予由用户ALTER DEFAULT PRIVILEGES FOR ROLE group_x创建的将来对象

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