【问题标题】:In postgres, when transfering a schema to a role, the role still cannot access tables in that schema在 postgres 中,将架构转移到角色时,角色仍然无法访问该架构中的表
【发布时间】:2015-04-01 15:40:53
【问题描述】:

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

在外壳中:

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 脚本逐个表访问?

【问题讨论】:

    标签: postgresql


    【解决方案1】:

    想通了:

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

    来自grant 文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      • 2021-06-18
      • 2016-12-28
      • 2010-11-12
      • 2011-12-08
      • 2011-04-10
      • 1970-01-01
      相关资源
      最近更新 更多