V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Veneris
V2EX  ›  PostgreSQL

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

  •  
  •   Veneris · 2021-08-19 13:53:49 +08:00 · 1245 次点击
    这是一个创建于 971 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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-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
        2
    dzdh  
       2021-08-26 14:50:05 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5374 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 09:31 · PVG 17:31 · LAX 02:31 · JFK 05:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.