--进入容器例如postgres
docker exec -it 容器id bash
--psql命令以某个用户进入postgres数据库
psql -U 用户名称-d 数据库
授权用户只读权限 --创建角色
CREATE role 角色名称;
--创建用户
CREATE USER 用户名 WITH PASSWORD '密码';
--授权select(历史表)
GRANT SELECT ON ALL TABLES IN schema public TO 角色名称;
--设置默认(可以访问新建的表)
alter default privileges in schema public grant select on tables to 角色名称;
--授权角色给用户
GRANT 角色名称 TO 用户名;
--取消角色readaccess包含select的所有权限
revoke all on all tables in schema public from 角色名称;
--取消用户itmario包含select的所有权限
revoke all on all tables in schema public from 用户名;
--删除用户角色
drop role 角色名称;
--删除用户
drop user itmario;
--设置默认授权所有权限表给用户用户名
alter default privileges in schema public grant all privileges on tables to 用户名;
--设置默认授权所有权限序列给用户itmario
alter default privileges in schema public grant all on sequences to 用户名;
--回收/取消默认授权所有权限表给用户itmario
alter default privileges in schema public revoke all privileges on tables from 用户名;
--回收/取消默认授权所有权限序列给用户itmario
alter default privileges in schema public revoke all on sequences from 用户名;
参考资料
PostgreSQL 创建只读用户,并开放特定的表。(实例)_那后生的博客-CSDN博客
远程链接报错信息
The authentication type 10 is not supported. Check that you have configured the pg_hba.conf file to include the client's IP address or subnet, and that it is using an authentication scheme supported by the driver.
修改pg_hba.conf配置文件当中的ipv4如下
# IPv4 local connections:
#host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 trust
The authentication type 10 is not supported - 简书
重新加载生效
select pg_reload_conf();