postgresql赋予用户只读权限以及新加的表也要有只读权限问题

关于postgresql数据库的只读权限问题

以下操作可以让只读用户对新加的表也有只读权限

创建用户及指定密码:
(1)CREATE USER readonly WITH ENCRYPTED PASSWORD 'ropass';
设置用户默认事务只读:
(2)alter user readonly set default_transaction_read_only=on;
赋予用户权限,查看public模式下所有表:
(3)GRANT USAGE ON SCHEMA public to readonly;4)ALTER DEFAULT PRIVILEGES FOR USER XXX(备注:owner) IN SCHEMA public GRANT SELECT ON TABLES TO readonly; 
赋予用户连接数据库权限:
(5)GRANT CONNECT ON DATABASE foo to readonly;
切换到指定数据库:
(6)\c athena
赋予用户表、序列查看权限:
(7)GRANT USAGE ON SCHEMA public to readonly;8)GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO readonly;9)GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly;```

你可能感兴趣的:(运维收获,postgresql,linux,数据库)