V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Veneris

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

  •  
  •   Veneris · Aug 19, 2021 · 1853 views
    This topic created in 1711 days ago, the information mentioned may be changed or developed.
    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 replies    2021-08-26 14:50:05 +08:00
    encro
        1
    encro  
       Aug 19, 2021
    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  
       Aug 26, 2021
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3339 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 00:04 · PVG 08:04 · LAX 17:04 · JFK 20:04
    ♥ Do have faith in what you're doing.