本文我们解释如何查看PostgreSQL 表结构以及权限列表,即哪些用户对表拥有哪些权限。
d+ table_name;
示例:
test=# d+ books数据表 "public.books"栏位 | 类型 | Collation | Nullable | Default | 存储 | 统计目标 | 描述
--------+---------+-----------+----------+-----------------------------------+----------+----------+------id | integer | | not null | nextval('books_id_seq'::regclass) | plain | |client | text | | not null | | extended | |data | jsonb | | not null | | extended | |
索引:"books_pkey" PRIMARY KEY, btree (id)
首先通过PostgreSQL的元数据查看,另外也可以直接查看数据表。
lumns
示例:
SELECT *
FROM lumns
where table_name ='books'
table_catalog | table_schema | table_name | column_name | ordinal_position | column_default | is_nullable | data_type | character_maximum_length | character_octet_length | numeric_precision | numeric_precision_radix | numeric_scale | datetime_precision | interval_type | interval_precision | character_set_catalog | character_set_schema | character_set_name | collation_catalog | collation_schema | collation_name | domain_catalog | domain_schema | domain_name | udt_catalog | udt_schema | udt_name | scope_catalog | scope_schema | scope_name | maximum_cardinality | dtd_identifier | is_self_referencing | is_identity | identity_generation | identity_start | identity_increment | identity_maximum | identity_minimum | identity_cycle | is_generated | generation_expression | is_updatable |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
test | public | books | id | 1 | nextval(‘books_id_seq’::regclass) | NO | integer | 32 | 2 | 0 | test | pg_catalog | int4 | 1 | NO | NO | NO | NEVER | YES | ||||||||||||||||||||||||
test | public | books | client | 2 | NO | text | 1073741824 | test | pg_catalog | text | 2 | NO | NO | NO | NEVER | YES | |||||||||||||||||||||||||||
test | public | books | data | 3 | NO | jsonb | test | pg_catalog | jsonb | 3 | NO | NO | NO | NEVER | YES |
test=# select * from books where 1=2;id | client | data
----+--------+------
(0 行记录)
上面介绍了几种方法查看表结构,下面我们查看哪些用户拥有表的权限列表。
使用 z
命令,后面跟上需要查看的表名称:
test=# z books存取权限架构模式 | 名称 | 类型 | 存取权限 | 列特权 | 策略
----------+-------+--------+---------------------------+--------+------public | books | 数据表 | postgres=arwdDxt/postgres+| || | | alice=rw/postgres | |
(1 行记录)
列出两个用户的权限情况。
我们通过元数据视图 le_table_grants
查看,同时使用 string_agg
函数对用户进行分组:
SELECT grantee, string_agg( privilege_type,', ' ) as privilege_type
FROM le_table_grants
WHERE table_name='books'
group by grantee
返回结果:
grantee | privilege_type |
---|---|
alice | SELECT, UPDATE |
postgres | UPDATE, DELETE, INSERT, REFERENCES, TRIGGER, TRUNCATE, SELECT |
列存两个用户不同的权限列表。
本文介绍使用命令方式和SQL方式查看PostgreSQL表结构和权限。
本文发布于:2024-02-02 10:29:37,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170684097843205.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |