postgresql 表权限查询

hankdb_1=> grant usage on schema hank to select_hank;
hankdb_1=> \z tb1
Access privileges
Schema | Name | Type | Access privileges | Column access privileges
--------+------+-------+-------------------+--------------------------
hank | tb1 | table | |
(1 row)

hankdb_1=> grant select on all tables in schema hank to select_hank;
GRANT
hankdb_1=> \z tb1
Access privileges
Schema | Name | Type | Access privileges | Column access privileges
--------+------+-------+--------------------+--------------------------
hank | tb1 | table | hank=arwdDxt/hank +|
| | | select_hank=r/hank |


Access privileges 具体含义:
a: insert
r: select
w: update
d: delete
x: references
t: trigger
D: truncate
已经生效:
postgres=# \c hankdb_1 select_hank
hankdb_1=> select * from hank.zhh;
a
---
1
查询视图:
select relname,relacl from pg_class where relname='zhh';
hankdb=> \c hankdb hank
You are now connected to database "hankdb" as user "hank".
hankdb=> select relname,relacl from pg_class where relname='zhh';
relname | relacl
---------+----------------------------------------
zhh | {hank=arwdDxt/hank,select_hank=r/hank}
查看用户权限:
hankdb=> select * from INFORMATION_SCHEMA.role_table_grants where grantee='select_hank';
grantor | grantee | table_catalog | table_schema | table_name | privilege_type | is_grantable | with_hierarchy
---------+-------------+---------------+--------------+------------+----------------+--------------+----------------
hank | select_hank | hankdb | hank | tb2 | SELECT | NO | NO
hank | select_hank | hankdb | hank | zhh | SELECT | NO | NO

对未来新建表赋予相关权限:

hankdb=> \z zhh
Access privileges
Schema | Name | Type | Access privileges | Column access privileges
--------+------+-------+--------------------+--------------------------
hank | zhh | table | hank=arwdDxt/hank +|
| | | select_hank=r/hank |
(1 row)

hankdb=> \z tb2
Access privileges
Schema | Name | Type | Access privileges | Column access privileges
--------+------+-------+--------------------+--------------------------
hank | tb2 | table | hank=arwdDxt/hank +|
| | | select_hank=r/hank |
(1 row)

hankdb=> create table tb3(a int);
CREATE TABLE
hankdb=> \z tb3
Access privileges
Schema | Name | Type | Access privileges | Column access privileges
--------+------+-------+-------------------+--------------------------
hank | tb3 | table | |
(1 row)

hankdb=> alter default privileges in schema hank grant select on tables to select_hank;
ALTER DEFAULT PRIVILEGES
hankdb=> create table tb4(a int);
CREATE TABLE
hankdb=> \z tb4
Access privileges
Schema | Name | Type | Access privileges | Column access privileges
--------+------+-------+--------------------+--------------------------
hank | tb4 | table | hank=arwdDxt/hank +|
| | | select_hank=r/hank |
(1 row)

hankdb=> \z tb3
Access privileges
Schema | Name | Type | Access privileges | Column access privileges
--------+------+-------+-------------------+--------------------------
hank | tb3 | table | |
(1 row)

参考:http://www.postgresql.org/docs/9.2/static/sql-grant.html

http://www.postgresql.org/docs/9.2/static/sql-alterdefaultprivileges.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值