postgreSql
創建用戶並授權
創建只讀用戶,控制用戶訪問權限
-
創建數據爲
CREATE DATABASE data_transfer;
-
pg 默認所有用戶都可以在名稱爲
public
的schema
中創建表,只讀用戶不允許創建,所以要收回此權限
revoke create on schema public from public;
-
創建schmea
create schema data_out
-
創建只讀用戶
readonly
create user readonly with password 'password';
-
授權用戶使用
data_out
權限
grant usage on schema data_out to readonly;
-
授權用戶查看
schema data_out
下的所有表(此時庫的的所有表,新增表不能看到)
grant select on all tables in schema data_out to readonly;
-
授權
readonly
用戶查看新創建表的select
權限
alter default privileges in schema data_out grant select on tables to readonly;
在指定數據爲執行,回收連接public權限,防止已經創建的庫未設置權限,表被訪問到
revoke connect on database rohs from public;
schema
操作
- 創建
schema
指定owner
默認是誰創建的schema
,owner
就是誰,可以通過如下方式進行指定
hadoop=# create schema schema_data_out authorization readonly;
CREATE SCHEMA
hadoop=# create schema authorization sha;
CREATE SCHEMA
hadoop=# \dn
List of schemas
Name | Owner
---------------------+----------
sha | sha
public | postgres
schema_data_out | readonly
(3 rows)
指定了
owner
,不指定schema
,則schema
名字與owner
一致。