PostgreSQL创建只读用户

  • Post author:
  • Post category:其他


创建用户及指定密码:

1


create user


zhangyou


with encrypted password

'

123456

'



;

设置用户默认事务只读:

1


alter user


zhangyou






set default_transaction_read_only=on;

赋予用户权限,查看public模式下所有表:

1

2


grant usage on schema public to


zhangyou


;


alter default privileges in


schema public grant select on tables to




zhangyou


;

赋予用户连接数据库权限:

1


grant connect on database


test


to


zhangyou


;

切换到指定数据库:

1


\c


test


赋予用户表、序列查看权限:

1

2

3


GRANT USAGE ON SCHEMA public to


zhangyou


;


GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO


zhangyou


;


GRANT SELECT ON ALL TABLES IN SCHEMA public TO


zhangyou


;



版权声明:本文为JDBogdan原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。