当普通用户访问某个模式下的对象时,需要对对象授权,也需要对模式授权。
[teledb@localhost bin]$ ./telesql -p 11111 -U teledb -d teledb
Password for user teledb:
telesql (TeleDB V6)
Type "help" for help.
- 创建schema
teledb=# create schema test; CREATE SCHEMA
- 创建表
teledb=# create table test.t1(id int); CREATE TABLE
- 创建用户user1
teledb=# create role user1 with login password 'User@184'; CREATE ROLE
- 给用户user1授权表访问权限
teledb=# grant select on test.t1 to user1; GRANT
示例:
- 切换至普通用户user1,尝试访问test.t1表。由于没有授权test模式,仍然无法访问。
teledb=# \c - user1 Password for user user1: You are now connected to database "teledb" as user "user1". teledb=> select * from test.t1; ERROR: permission denied for schema test LINE 1: select * from test.t1; ^
- 切换至teledb用户,将test模式的访问权限授权给user1,重新用user1访问t1表。
teledb=> \c - teledb Password for user teledb: You are now connected to database "teledb" as user "teledb". -- 授权schema teledb=# grant usage on schema test to user1; GRANT teledb=# \c - user1 Password for user user1: You are now connected to database "teledb" as user "user1". teledb=> select * from test.t1; id ---- (0 rows)