简体   繁体   English

无法在 Postgres 上向新用户授予所有权限

[英]Unable to grant all privileges to new user on Postgres

I'm creating a new user in a Postgres database (AWS RDS) and trying to grant all privileges on all tables in public schema of an existing database to that user.我正在 Postgres 数据库 (AWS RDS) 中创建一个新用户,并尝试将现有数据库的公共架构中所有表的所有权限授予该用户。 It is failing with below error.它失败并出现以下错误。 I even tried after logging in as the rds_superuser (postgres) and got the same error.我什至在以 rds_superuser (postgres) 身份登录后进行了尝试,并得到了同样的错误。

psql (13.3, server 10.15) psql(13.3,服务器 10.15)

test_db=> \dt
              List of relations
 Schema |     Name     | Type  |    Owner     
--------+--------------+-------+--------------
 public | table1       | table | test_user
 public | table2       | table | test_user
 public | table3       | table | test_user
(3 rows)

test_db=> CREATE ROLE new_user WITH LOGIN PASSWORD 'by1ne8Cs0Z2' VALID UNTIL '2021-05-29';
CREATE ROLE

test_db=> GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO new_user;

ERROR: permission denied for relation table1错误:关系表 1 的权限被拒绝

Can someone help me out here?有人可以帮我吗?

EDIT: Found a workaround but not sure if this is the best approach.编辑:找到了解决方法,但不确定这是否是最好的方法。 Logged in as the postgres user, ran the below query and then logged back in as the new_user and was able to run select queries on the tables.以 postgres 用户身份登录,运行以下查询,然后以 new_user 身份重新登录,并能够对表运行 select 查询。

test_db=> \du new_user
                                 List of roles
    Role name    |                 Attributes                  |   Member of    
-----------------+---------------------------------------------+----------------
 new_user        | Password valid until 2021-05-29 00:00:00+00 | {}

test_db=> GRANT test_user to new_user;

test_db=> \du new_user
                                 List of roles
    Role name    |                 Attributes                  |   Member of    
-----------------+---------------------------------------------+----------------
 new_user        | Password valid until 2021-05-29 00:00:00+00 | {test_user}

EDIT2: Please find the output below. EDIT2:请在下面找到 output。

test_db=> \dp table1 
                               Access privileges
 Schema |    Name    | Type  | Access privileges | Column privileges | Policies 
--------+------------+-------+-------------------+-------------------+----------
 public | table1     | table |                   |                   | 
(1 row)

You have to issue the GRANT statements as user test_user .您必须以用户test_user的身份发出GRANT语句。

Only the owner can grant privileges on an object (or a user who has been granted the privilege WITH GRANT OPTION ).只有所有者可以授予 object 的权限(或已被授予权限WITH GRANT OPTION的用户)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM