浅谈PostgreSQL用户权限
# 创建用户lottu1postgres
=# createuser lottu1;CREATE ROLE# 创建用户lottu2
postgres
=# createuser lottu2;CREATE ROLE# 创建数据库db1;属于lottu1
postgres
=# createdatabase db1 owner lottu1;CREATEDATABASE# 创建schema、
table、并插入记录postgres
=# c db1 lottu1;You are now connected
todatabase "db1" asuser "lottu1".db1
=>createschema lottu1;CREATESCHEMAdb1
=>createtable tbl_lottu_01(id int, info text, reg_time timestamp);CREATETABLEdb1
=>insertinto tbl_lottu_01 select1,"lottu",now();INSERT01
db1=> c db1 lottu2You are now connected
todatabase "db1" asuser "lottu2".
db1=> c db1 postgresYou are now connected
todatabase "db1" asuser "postgres".db1
=# revoke CONNECT ONDATABASE db1 frompublic;REVOKEdb1
=# c db1 postgresYou are now connected
todatabase "db1" asuser "postgres".db1
=# c db1 lottu1;You are now connected
todatabase "db1" asuser "lottu1".db1
=> c db1 lottu2;FATAL: permission denied
fordatabase "db1"DETAIL:
User does not have CONNECT privilege.Previous connection kept
db1=>grant CONNECT ONDATABASE db1 to lottu2;GRANTdb1
=>grant USAGE ONSCHEMA lottu1 to lottu2;GRANTdb1
=>grantselectonTABLE tbl_lottu_01 to lottu2;GRANTdb1
=> c db1 lottu2;You are now connected
todatabase "db1" asuser "lottu2".db1
=>select*from lottu1.tbl_lottu_01;id
| info | reg_time ----+-------+----------------------------1| lottu |2020-05-1910:50:15.206569
(1 row)
grantselectonALL TABLES INSCHEMA lottu1 to lottu2;
以上是 浅谈PostgreSQL用户权限 的全部内容, 来源链接: utcz.com/z/533723.html