欧美free性护士vide0shd,老熟女,一区二区三区,久久久久夜夜夜精品国产,久久久久久综合网天天,欧美成人护士h版

目錄

postgresql常用創(chuàng)建用戶和授權

在PostgreSQL中,創(chuàng)建用戶和授權是非常常見的管理任務。

需求

(1)給用戶a創(chuàng)建一個數(shù)據(jù)庫,并且給a用戶對這個庫有所有權限

(2)給read_a用戶對這個數(shù)據(jù)庫有只讀權限

步驟

1.創(chuàng)建用戶a

2.創(chuàng)建數(shù)據(jù)庫db_a, 并設置owner為a

3.回收默認的public schema create權限

4.設置db_a的public schema 默認的owner 為a

5.創(chuàng)建只讀用戶read_a

6.用a用戶給read_a用戶設置默認的權限

7.給read_a用戶設置對public schema 查詢權限

具體操作如下:

db_test=# create user a with password '1234';        # 1. 創(chuàng)建用戶a

CREATE ROLE

db_test=# create database db_a with owner a;         # 2. 創(chuàng)建數(shù)據(jù)庫db_a, owner為a

CREATE DATABASE    

db_test=# \c db_a;

You are now connected to database "db_a" as user "postgres".

db_a=# revoke create on schema public from public;    # 3. 回收默認public create權限, 這樣就不是每個人都可以在這里創(chuàng)建表了

REVOKE

db_a=# \dn

  List of schemas

  Name  |  Owner   

--------+----------

 public | postgres

(1 row)

db_a=# alter schema  public owner to a;              # 4. 設置db_a 的public schema的owner 為a

ALTER SCHEMA

db_a=# \dn

List of schemas

  Name  | Owner 

--------+-------

 public | a

(1 row)

db_a=# create user read_a with password '1234';       # 5. 創(chuàng)建只讀用戶read_a

CREATE ROLE

db_a=# \c - a                                         # 切換到用戶a, db_a數(shù)據(jù)庫

You are now connected to database "db_a" as user "a".

db_a=> alter default privileges in schema public grant select on tables to read_a;     # 6. 修改默認權限   

ALTER DEFAULT PRIVILEGES

db_a=> GRANT USAGE ON SCHEMA public to read_a;        # 6.授權read_a 對public schema權限

GRANT

db_a=> GRANT SELECT ON ALL TABLES IN SCHEMA  public to read_a;    # 授權read_a 對public schema權限

GRANT

db_a=> \ddp

         Default access privileges

 Owner | Schema | Type  | Access privileges 

-------+--------+-------+-------------------

 a     | public | table | read_a=r/a

(1 row)

postgres=> \c db_a                # 用a用戶創(chuàng)建一個表t2,插入語句,用read_a查詢測試一下

You are now connected to database "db_a" as user "a".

db_a=> \dt

       List of relations

 Schema | Name | Type  | Owner 

--------+------+-------+-------

 public | t1   | table | a

(1 row)

db_a=> create table t2(id int);

CREATE TABLE

db_a=> insert into t2(id) values(1);

INSERT 0 1

db_a=> \c - read_a;            # 切換到read_a用戶,測試查詢t2表

You are now connected to database "db_a" as user "read_a".

db_a=> 

db_a=> \dt

       List of relations

 Schema | Name | Type  | Owner 

--------+------+-------+-------

 public | t1   | table | a

 public | t2   | table | a

(2 rows)

db_a=> select * from t2;

 id 

----

  1

(1 row)


本文內容根據(jù)網(wǎng)絡資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點和立場。

轉載請注明,如有侵權,聯(lián)系刪除。

本文鏈接:http://gantiao.com.cn/post/18461059.html

發(fā)布評論

您暫未設置收款碼

請在主題配置——文章設置里上傳

掃描二維碼手機訪問

文章目錄