一、配置说明:

角色名称:user01 

1.user01权限说明:

连接test数据库,未授权时无法连接其它数据库;

在指定schema,建立\查看\删除表,查看schema中对象;

2.其它普通用户:

无法连接test数据库及schema(sales)中对象,需要授权;

二、操作步骤:

  1. instance(实例级): role(角色)

$ psql postgres

postgres=# CREATE ROLE user01 LOGIN NOSUPERUSER NOCREATEDB;

2.database(数据库级): CREATE(schemas) and CONNECT(database)

$ psql postgres

postgres=# CREATE DATABASE test;

postgres=# REVOKE ALL ON DATABASE test FROM public; -- 禁止其它普通role连接test

postgres=# GRANT CONNECT ON DATABASE test TO user01;

3.schema(架构级):

CREATE(put object into schema)

USAGE (allow us to actually look into a schema and see which objects are present).

$psql test

test=# REVOKE ALL ON SCHEMA public FROM public;-- 其它普通role无法连接test

test=# CREATE SCHEMA sales;

CREATE SCHEMA

test=# GRANT CREATE,USAGE ON SCHEMA sales TO user01; -- user01 可以在sales中建立、查看对象

GRANT

test=# \q

$ psql test -U user01

test=> CREATE TABLE sales.t_sales (id int4);

CREATE TABLE

4.table(表级): grant 

默认user01创建、drop表和DML表内容

5.column(列级):grant

默认user01创建、drop表和DML列内容