在postgres中,当将模式转移到角色时,该角色仍然无法访问该模式中的表

时间:2015-02-02 16:19:07

标签: postgresql

我想授予用户对现有架构的完全访问权限。当我将架构的所有权转移给该用户时,用户无法访问这些表。这是一个例子:

在shell中:

createdb test
psql -d test

在postgres中:

create table table_a (
    code char(2)
);
CREATE TABLE
Time: 4.261 ms
create table table_b (
    code char(2)
);
CREATE TABLE
Time: 4.261 ms

create role user_b with login;

alter schema public owner to user_a;

以其他角色登录postgres:

psql -d test -U user_b

在postgres中:

\dt
    List of relations
 Schema |  Name   | Type  | Owner
--------+---------+-------+--------
 public | table_a | table | doved
 public | table_b | table | doved

select * from table_a;
ERROR:  42501: permission denied for relation table_a

create table table_c (
    code char(2)
);

select * from table_c;
code
------
(0 rows)

user_b可以在其架构中创建新表,但不能访问其中的现有表(除非转移了表的所有权)。是否有一种简单的方法可以授予该用户对模式的完全访问权限,而无需通过shell脚本逐个表进行访问?

1 个答案:

答案 0 :(得分:0)

想出来:

GRANT ALL PRIVILEGES on ALL TABLES IN SCHEMA public to user_a;

来自grant文档。