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

2021-08-19 13:53:49 +08:00
 Veneris
  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 权限?

1260 次点击
所在节点    PostgreSQL
2 条回复
encro
2021-08-19 20:40:00 +08:00
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
2021-08-26 14:50:05 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/796752

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX