Veneris
V2EX  ›  PostgreSQL

如何设置 PostgreSQL 新角色的默认权限?

By Veneris at 2021 年 8 月 19 日 · 2274 次点击
  1. 新建 database 后,默认的 public schema 是所有 role 都有权限的,只能revoke all on schema public from public,但是也仅在当前 database 生效,以后新建的 database 仍然需要执行一遍。能否新 database 的 public schema 需要手动 grant 给其他角色?

  2. 新建 role 后,默认能 connect 到所有 databse,只能revoke connect on database from *role*,而且需要一个一个库来 revoke,能否改为在默认是不能连接的,需要手动 grant connect 权限?

2 条回复  •  2021-08-26 14:50:05 +08:00
encro
   1
encro  
   2021 年 8 月 19 日
https://www.postgresql.org/docs/12/app-createuser.html


CREATE ROLE joe NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;


https://medium.com/coding-blocks/creating-user-database-and-adding-access-on-postgresql-8bfcd2f4a91e

sudo -u postgres psql
postgres=# create database mydb;
postgres=# create user myuser with encrypted password 'mypass';
postgres=# grant all privileges on database mydb to myuser;


如果不行,可能是 hba 文件配置问题。
dzdh
   2
dzdh  
   2021 年 8 月 26 日
© 2026 V2EX · 24ms · 3.9.8.5