pgsql 9.4修改数据库只读

先进入psql

 

切换到目标数据库

\c mydb

 

对于老表

grant usage on schema public to $read_only_user;
grant select on all tables in schema public to $read_only_user;

 

设置默认,对于未创建的表直接默认赋予只读权限

alter default privileges for user $db_owner in schema public grant select on tables to $read_only_user;

pubic这个schema是默认的schema

 

阿里云得创建superuser,然后赋予default_transaction_read_only属性,不然貌似不行

select usename,useconfig from pg_user where usename='xxx';
alter role xxx set default_transaction_read_only=true;
select usename,useconfig from pg_user where usename='xxx';

推荐用这个,简单方便

 

测试建表语句

create table t2 ( id serial, name varchar(64) );

 

posted @ 2016-07-15 16:38  自由出土文物  阅读(764)  评论(0编辑  收藏  举报