Val*_*lva 4 postgresql postgresql-9.4
我当前的数据库uat
作为 owner postgres
。但现在我想设置具有正确权限的角色和用户。一些简单的东西,比如:
角色:dba
,developer
,application
用户: dba1
, dev1
, dev2
,app1
哪里dba
可以在数据库上做任何事情以进行管理;developer
可以进行SELECT
,UPDATE
和INSERT
, 通常的开发人员操作;app1
与developer
角色相同的操作,暂时。
我怎样才能正确地做到这一点?production
在这个新设置中,谁应该是我表的所有者?
更新:
------------------------
-- INITIAL SETUP
------------------------
-- create uat database
create database uat;
-- dba role
create role dba with superuser createdb createrole nologin replication bypassrls;
-- dev role
create role dev with nosuperuser nocreatedb nocreaterole nologin noreplication nobypassrls;
-- app role
create role app with nosuperuser nocreatedb nocreaterole nologin noreplication nobypassrls;
-- alter postgres password
alter role postgres encrypted password '';
-- create users
create user dev1 login inherit encrypted password '' in role dev;
create user dev2 login inherit encrypted password '' in role dev;
create user dev3 login inherit encrypted password '' in role dev;
create user dev4 login inherit encrypted password '' in role dev;
create user webapp encrypted password '' in role app;
-- grant privileges to dba role
grant all privileges on all tables in schema public to dba;
------------------------
-- RESTORE
------------------------
psql -U postgres -d uat -h localhost -W -p 5432 < uat.sql
Run Code Online (Sandbox Code Playgroud)
但是当我以用户dev1
身份登录时,我什么也做不了:
select * from guru_basket_security;
Run Code Online (Sandbox Code Playgroud)
此表的列表访问权限:
\z
Access privileges
Schema | Name | Type | Access privileges | Column privileges | Policies
--------+------------------------------------------------------+----------+---------------------------+-------------------+----------
public | guru_basket_security | table | | |
public | identifier | table | postgres=arwdDxt/postgres | |
Run Code Online (Sandbox Code Playgroud)
我收到了这些错误:
ERROR: permission denied for relation guru_basket_security
ERROR: permission denied for relation identifier
Run Code Online (Sandbox Code Playgroud)
小智 5
组和用户的概念在 PostgreSQL 中基本上已被取消,术语 USER 和 GROUP 可以与 ROLE 互换使用。请参阅文档。
可以说您想要做的是首先像这样创建您的“组”角色:
CREATE ROLE devs NOLOGIN;
Run Code Online (Sandbox Code Playgroud)
然后向开发人员授予所有所需的权限。现在用IN ROLE devs
子句创建用户,如下所示:
CREATE ROLE jsmith LOGIN INHERIT IN ROLE devs ENCRYPTED PASSWORD '...' ...;
CREATE ROLE sjones LOGIN INHERIT IN ROLE devs ENCRYPTED PASSWORD '...' ...;
...
Run Code Online (Sandbox Code Playgroud)
这将允许“真实”用户登录并继承所有相同的权限,但没有人可以明确成为开发人员(或“组”角色)。
归档时间: |
|
查看次数: |
12007 次 |
最近记录: |