先进入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) );