Grant database priviledges does not grant table access privileges

时间:2016-03-02 10:59:10

标签: postgresql

After granting access privileges to a user using this command:

GRANT ALL PRIVILEGES ON DATABASE my_newly_created_db_name TO my_user_name;

I find that the granted user still does not have access privileges on the tables inside that database. I checked the privileges on tables using this command:

SELECT grantee, string_agg(privilege_type, ', ') AS privileges
FROM information_schema.role_table_grants 
WHERE table_name='a_table'   
GROUP BY grantee;

I wonder if this is the default behaviour of the first grant on database command. I didn't find much info about this on the official doc

Do I need to restart the database to enable the new privileges?

1 个答案:

答案 0 :(得分:0)

数据库和表是两回事。查看数据库的语法。

GRANT { { CREATE | CONNECT | TEMPORARY | TEMP } [, ...] | ALL [ PRIVILEGES ] }
    ON DATABASE database_name [, ...]
    TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]

授予所有权限on database database_name包括创建数据库,连接到它们以及创建临时表的权限。这就是全部。

在单个表格上使用grant all,或在all tables in schema schema_name上使用NSTimer.scheduledTimerWithTimeInterval() 授予选择,插入,更新等功能。

GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER }
    [, ...] | ALL [ PRIVILEGES ] }
    ON { [ TABLE ] table_name [, ...]
         | ALL TABLES IN SCHEMA schema_name [, ...] }
    TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]

另一种选择是change the default privileges in one or more schemas

ALTER DEFAULT PRIVILEGES
    [ FOR { ROLE | USER } target_role [, ...] ]
    [ IN SCHEMA schema_name [, ...] ]
    abbreviated_grant_or_revoke

where abbreviated_grant_or_revoke is one of:

GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER }
    [, ...] | ALL [ PRIVILEGES ] }
    ON TABLES
    TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
相关问题