Case:一個read-only角色對某個schema下的新建的表,無需單獨(dú)授權(quán),直接擁有只讀權(quán)

Case: 一個read-only 角色對某個schema下的新建的表,無需單獨(dú)授權(quán),直接擁有只讀權(quán)限

創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比關(guān)嶺網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式關(guān)嶺網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋關(guān)嶺地區(qū)。費(fèi)用合理售后完善,十余年實(shí)體公司更值得信賴。

首先,你要知道PostgreSQL默認(rèn)schema下新建的表,對于一個普通用戶不會有select的權(quán)限的,所以我需要修改PostgreSQl默認(rèn)的權(quán)限,把select提前賦予普通用戶,需要使用到alter default privileges這個命令


Session1 (user:postgres):

#psql

create role role1 password '123456' login;

create schema schema1;

grant usage on schema schema1 to role1;

testdb=# \dn+ schema1;

                     List of schemas

  Name   |  Owner   |  Access privileges   | Description

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

schema1 | postgres | postgres=UC/postgres+|

         |          | role1=U/postgres     |


alter default privileges in schema schema1 grant select on tables to role1;


testdb=# \ddp+

           Default access privileges

  Owner   | Schema  | Type  | Access privileges

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

postgres | schema1 | table | role1=r/postgres


create table schema1.t1(c1 int,c2 varchar(10));

insert into schema1.t1 values(1,'aaa');


testdb=# \dp+

                                 Access privileges

Schema  | Name | Type  |     Access privileges     | Column privileges | Policies

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

schema1 | t1   | table | postgres=arwdDxt/postgres+|                   |

         |      |       | role1=r/postgres          |                   |


Session2 read_only:


#psql -h 172.16.101.54 -p 5432 testdb role1

testdb=> select * from schema1.t1;

c1 | c2  

----+-----

  1 | aaa

(1 row)

分享文章:Case:一個read-only角色對某個schema下的新建的表,無需單獨(dú)授權(quán),直接擁有只讀權(quán)
網(wǎng)頁路徑:http://muchs.cn/article16/iidedg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、服務(wù)器托管網(wǎng)站排名、網(wǎng)站改版、網(wǎng)站設(shè)計(jì)公司外貿(mào)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司