最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

postgresql影子用戶實踐場景分析

 更新時間:2021年03月06日 11:03:53   作者:瀚高PG實驗室  
這篇文章主要介紹了postgresql影子用戶實踐場景分析,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

在實際的生產(chǎn)環(huán)境 ,我們經(jīng)常會碰到這樣的情況:因為業(yè)務場景需要,本部門某些重要的業(yè)務數(shù)據(jù)表需要給予其他部門查看權(quán)限,因業(yè)務的擴展及調(diào)整,后期可能需要放開更多的表查詢權(quán)限。為解決此種業(yè)務需求,我們可以采用創(chuàng)建視圖的方式來解決,已可以通過創(chuàng)建影子用戶的方式來滿足需求,本文主要介紹影子用戶的創(chuàng)建及授權(quán)方法。

場景1:只授予usage on schema 權(quán)限

session 1:
--創(chuàng)建readonly用戶,并將test模式賦予readonly用戶。

postgres=# create user readonly with password 'postgres';
CREATE ROLE
postgres=# grant usage on schema test to readonly;
​GRANT
postgres=# \dn
List of schemas
 Name | Owner 
-------+-------
 test | postgres

session 2:

--登陸readonly用戶可以查詢test模式下現(xiàn)存的所有表。

postgres=# \c postgres readonly 
You are now connected to database "postgres" as user "readonly".
postgres=> select * from test.emp ;
 empno | ename |  job  | mgr | hiredate |  sal  | comm  | deptno 
-------+--------+-----------+------+------------+---------+---------+--------
 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 |   30
 7521 | WARD  | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 |   30
 7566 | JONES | MANAGER  | 7839 | 1981-04-02 | 2975.00 |     |   20
 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 |   30
 7698 | BLAKE | MANAGER  | 7839 | 1981-05-01 | 2850.00 |     |   30
 7782 | CLARK | MANAGER  | 7839 | 1981-06-09 | 2450.00 |     |   10
 7839 | KING  | PRESIDENT |   | 1981-11-17 | 5000.00 |     |   10
 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 |  0.00 |   30
 7900 | JAMES | CLERK   | 7698 | 1981-12-03 | 950.00 |     |   30
 7902 | FORD  | ANALYST  | 7566 | 1981-12-03 | 3000.00 |     |   20
 7934 | MILLER | CLERK   | 7782 | 1982-01-23 | 1300.00 |     |   10
 7788 | test  | ANALYST  | 7566 | 1982-12-09 | 3000.00 |     |   20
 7876 | ADAMS | CLERK   | 7788 | 1983-01-12 | 1100.00 |     |   20
 1111 | SMITH | CLERK   | 7902 | 1980-12-17 | 800.00 |     |   20
(14 rows)

換到session 1創(chuàng)建新表t1

postgres=# create table test.t1 as select * from test.emp;
​CREATE TABLE

切換到session 2 readonly用戶下,t1表無法查詢

postgres=> select * from test.t1 ;
2021-03-02 15:25:33.290 CST [21059] ERROR: permission denied for table t1
2021-03-02 15:25:33.290 CST [21059] STATEMENT: select * from test.t1 ;
**ERROR: permission denied for table t1

結(jié)論:如果只授予 usage on schema 權(quán)限,readonly 只能查看 test 模式下已經(jīng)存在的表和對象。在授予 usage on schema 權(quán)限之后創(chuàng)建的新表無法查看。

場景2:授予usage on schema 權(quán)限之后,再賦予 select on all tables in schema 權(quán)限

針對上個場景session 2 **ERROR: permission denied for table t1 錯誤的處理

postgres=> select * from test.t1 ;
**ERROR: permission denied for table t1

session 1: 使用postgres用戶授予readonly用戶 select on all tables 權(quán)限

postgres=# grant select on all tables in schema test TO readonly ;

session 2: readonly用戶查詢 t1 表

postgres=> select * from test.t1;
 empno | ename |  job  | mgr | hiredate |  sal  | comm  | deptno 
-------+--------+-----------+------+------------+---------+---------+--------
 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 |   30
 7521 | WARD  | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 |   30
 7566 | JONES | MANAGER  | 7839 | 1981-04-02 | 2975.00 |     |   20
 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 |   30
 7698 | BLAKE | MANAGER  | 7839 | 1981-05-01 | 2850.00 |     |   30
 7782 | CLARK | MANAGER  | 7839 | 1981-06-09 | 2450.00 |     |   10
 7839 | KING  | PRESIDENT |   | 1981-11-17 | 5000.00 |     |   10
 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 |  0.00 |   30
 7900 | JAMES | CLERK   | 7698 | 1981-12-03 | 950.00 |     |   30
 7902 | FORD  | ANALYST  | 7566 | 1981-12-03 | 3000.00 |     |   20
 7934 | MILLER | CLERK   | 7782 | 1982-01-23 | 1300.00 |     |   10
 7788 | test  | ANALYST  | 7566 | 1982-12-09 | 3000.00 |     |   20
 7876 | ADAMS | CLERK   | 7788 | 1983-01-12 | 1100.00 |     |   20
 1111 | SMITH | CLERK   | 7902 | 1980-12-17 | 800.00 |     |   20
(14 rows)

session1 :postgres用戶的test模式下創(chuàng)建新表 t2

postgres=# create table test.t2 as select * from test.emp;
SELECT 14

session 2:readonly用戶查詢 t2 表權(quán)限不足

postgres=> select * from test.t2 ;
ERROR: permission denied for table t2

session 1:再次賦予 grant select on all tables

postgres=# grant select on all tables in schema test TO readonly ;

session 2:readonly用戶又可以查看 T2 表

postgres=> select * from test.t2 ;
 empno | ename |  job  | mgr | hiredate |  sal  | comm  | deptno 
-------+--------+-----------+------+------------+---------+---------+--------
 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 |   30
 7521 | WARD  | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 |   30
 7566 | JONES | MANAGER  | 7839 | 1981-04-02 | 2975.00 |     |   20
 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 |   30
 7698 | BLAKE | MANAGER  | 7839 | 1981-05-01 | 2850.00 |     |   30
 7782 | CLARK | MANAGER  | 7839 | 1981-06-09 | 2450.00 |     |   10
 7839 | KING  | PRESIDENT |   | 1981-11-17 | 5000.00 |     |   10
 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 |  0.00 |   30
 7900 | JAMES | CLERK   | 7698 | 1981-12-03 | 950.00 |     |   30
 7902 | FORD  | ANALYST  | 7566 | 1981-12-03 | 3000.00 |     |   20
 7934 | MILLER | CLERK   | 7782 | 1982-01-23 | 1300.00 |     |   10
 7788 | test  | ANALYST  | 7566 | 1982-12-09 | 3000.00 |     |   20
 7876 | ADAMS | CLERK   | 7788 | 1983-01-12 | 1100.00 |     |   20
 1111 | SMITH | CLERK   | 7902 | 1980-12-17 | 800.00 |     |   20
(14 rows)

影子用戶創(chuàng)建

如果想讓readonly只讀用戶不在每次 postgres用戶在test模式中創(chuàng)建新表后都要手工賦予 grant select on all tables in schema test TO readonly 權(quán)限。則需要授予對test默認的訪問權(quán)限,對于test模式新創(chuàng)建的也生效。

session 1:未來訪問test模式下所有新建的表賦權(quán),創(chuàng)建 t5 表。

postgres=# alter default privileges in schema test grant select on tables to readonly ;
ALTER DEFAULT PRIVILEGES
postgres=# create table test.t5 as select * from test.emp;
CREATE TABLE

session 2:查詢readonly用戶

postgres=> select * from test.t5;
 empno | ename |  job  | mgr | hiredate |  sal  | comm  | deptno 
-------+--------+-----------+------+------------+---------+---------+--------
 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 |   30
 7521 | WARD  | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 |   30
 7566 | JONES | MANAGER  | 7839 | 1981-04-02 | 2975.00 |     |   20
 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 |   30
 7698 | BLAKE | MANAGER  | 7839 | 1981-05-01 | 2850.00 |     |   30
 7782 | CLARK | MANAGER  | 7839 | 1981-06-09 | 2450.00 |     |   10
 7839 | KING  | PRESIDENT |   | 1981-11-17 | 5000.00 |     |   10
 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 |  0.00 |   30
 7900 | JAMES | CLERK   | 7698 | 1981-12-03 | 950.00 |     |   30
 7902 | FORD  | ANALYST  | 7566 | 1981-12-03 | 3000.00 |     |   20
 7934 | MILLER | CLERK   | 7782 | 1982-01-23 | 1300.00 |     |   10
 7788 | test  | ANALYST  | 7566 | 1982-12-09 | 3000.00 |     |   20
 7876 | ADAMS | CLERK   | 7788 | 1983-01-12 | 1100.00 |     |   20
 1111 | SMITH | CLERK   | 7902 | 1980-12-17 | 800.00 |     |   20
(14 rows)

總結(jié):影子用戶創(chuàng)建的步驟

--創(chuàng)建影子用戶
create user readonly with password 'postgres';
--將schema中usage權(quán)限賦予給readonly用戶,訪問所有已存在的表
grant usage on schema test to readonly;
grant select on all tables in schema test to readonly;
--未來訪問test模式下所有新建的表
alter default privileges in schema test grant select on tables to readonly ;

到此這篇關(guān)于postgresql影子用戶實踐的文章就介紹到這了,更多相關(guān)postgresql影子用戶內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • postgresql修改自增序列操作

    postgresql修改自增序列操作

    這篇文章主要介紹了postgresql修改自增序列操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-12-12
  • PostgreSql生產(chǎn)級別數(shù)據(jù)庫安裝要注意事項

    PostgreSql生產(chǎn)級別數(shù)據(jù)庫安裝要注意事項

    這篇文章主要介紹了PostgreSql生產(chǎn)級別數(shù)據(jù)庫安裝要注意事項,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-08-08
  • PostgreSQL中關(guān)閉死鎖進程的方法

    PostgreSQL中關(guān)閉死鎖進程的方法

    這篇文章主要介紹了PostgreSQL中關(guān)閉死鎖進程的方法,本文給出兩種解決這問題的方法,需要的朋友可以參考下
    2015-02-02
  • 詳解PostgreSQL 表分區(qū)與繼承

    詳解PostgreSQL 表分區(qū)與繼承

    本文將深入剖析PostgreSQL表分區(qū)與繼承的實現(xiàn)機理,結(jié)合最新版本(16版本)的特性演進,通過大量生產(chǎn)級代碼示例,揭示如何設(shè)計高效的分區(qū)方案、優(yōu)化分區(qū)查詢性能,并巧妙運用繼承特性構(gòu)建靈活的數(shù)據(jù)模型,感興趣的朋友一起看看吧
    2025-04-04
  • PostgreSQL之pgdump備份恢復操作

    PostgreSQL之pgdump備份恢復操作

    這篇文章主要介紹了PostgreSQL之pgdump備份恢復操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-12-12
  • postgresql查詢每個月的最后一天日期并對未查到的日期結(jié)果補0(操作示例)

    postgresql查詢每個月的最后一天日期并對未查到的日期結(jié)果補0(操作示例)

    這篇文章主要介紹了postgresql查詢每個月的最后一天日期,并對未查到的日期結(jié)果補0,pgsql需要使用函數(shù)使用date_trunc()函數(shù)找到指定月第一天,然后對該日期先加一個月在減一個月就能得到你傳給的日期的最后一天日期,感興趣的朋友跟隨小編一起看看吧
    2023-10-10
  • PostgreSQL教程(十九):SQL語言函數(shù)

    PostgreSQL教程(十九):SQL語言函數(shù)

    這篇文章主要介紹了PostgreSQL教程(十九):SQL語言函數(shù),本文講解了SQL語言函數(shù)基本概念、基本類型、復合類型、帶輸出參數(shù)的函數(shù)、返回結(jié)果作為表數(shù)據(jù)源等內(nèi)容,需要的朋友可以參考下
    2015-05-05
  • SpringBoot連接使用PostgreSql數(shù)據(jù)庫的方法

    SpringBoot連接使用PostgreSql數(shù)據(jù)庫的方法

    這篇文章主要介紹了SpringBoot連接使用PostgreSql數(shù)據(jù)庫的方法,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-01-01
  • PostgreSQL常用字符串函數(shù)與示例說明小結(jié)

    PostgreSQL常用字符串函數(shù)與示例說明小結(jié)

    文章介紹了PostgreSQL中常用字符串函數(shù)的使用方法,包括空值處理、字符串位置查詢、長度計算、大小寫轉(zhuǎn)換、去除空格、連接、替換、匹配、拆分和截取等操作,感興趣的朋友跟隨小編一起看看吧
    2024-11-11
  • PostgreSQL數(shù)據(jù)庫性能調(diào)優(yōu)的注意點以及pg數(shù)據(jù)庫性能優(yōu)化方式

    PostgreSQL數(shù)據(jù)庫性能調(diào)優(yōu)的注意點以及pg數(shù)據(jù)庫性能優(yōu)化方式

    這篇文章主要介紹了PostgreSQL數(shù)據(jù)庫性能調(diào)優(yōu)的注意點以及pg數(shù)據(jù)庫性能優(yōu)化方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-03-03

最新評論

安国市| 青铜峡市| 旌德县| 海淀区| 顺昌县| 丹阳市| 桂阳县| 合川市| 宾阳县| 顺昌县| 丁青县| 北流市| 南京市| 沭阳县| 隆安县| 保靖县| 工布江达县| 沁水县| 德兴市| 孟津县| 团风县| 高台县| 运城市| 莱芜市| 嘉定区| 土默特左旗| 垣曲县| 城固县| 小金县| 卫辉市| 吉木乃县| 保亭| 蚌埠市| 洪洞县| 丹棱县| 筠连县| 贡觉县| 肃宁县| 华宁县| 大安市| 丹寨县|