zl程序教程

您现在的位置是:首页 >  其他

当前栏目

PostgreSQL查不到新建表?

2023-02-25 18:20:33 时间

近期有同学反馈在使用PG数据库的时候,明明之前创建的账号已经授权了查看所有表的权限,为何却查不到新建表?到底该如何授权?

1. 常见授权脚本

创建用户test_user

create user test_user with password 'password';

授权用户使用public schema的权限

grant usage on schema public to test_user;

授权用户查看schema public下的所有表(授权时此库的的所有表,后续新增表不能看到)

grant select on all tables in schema public to test_user;

授权test_user用户查看新创建表的select 权限

alter default privileges in schema public grant select on tables to test_user;

授予指定schema 下所有数据表及序列的权限


grant all privileges on all tables in schema public to test_user;
grant all privileges on all sequences in schema public to test_user;

2. 查看用户权限

很多时候也需要查看用户有哪些权限,因此常见的权限查看脚本如下

查看某用户的系统权限

SELECT * FROM  pg_roles WHERE rolname='test_user';

查看某用户的表权限

select * from information_schema.table_privileges where grantee='test_user';

查看某用户的usage权限

select * from information_schema.usage_privileges where grantee='test_user';

查看某用户在存储过程函数的执行权限

select * from information_schema.routine_privileges where grantee='test_user';

查看某用户在某表的列上的权限

select * from information_schema.column_privileges where grantee='test_user';

查看当前用户能够访问的数据类型

select * from information_schema.data_type_privileges ;

查看用户自定义类型上授予的USAGE权限

select * from information_schema.udt_privileges where grantee='test_user';