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

Postgresql 賦予用戶權(quán)限和撤銷權(quán)限的實(shí)例

 更新時(shí)間:2021年01月04日 10:02:58   作者:Jason''s_Blog  
這篇文章主要介紹了Postgresql 賦予用戶權(quán)限和撤銷權(quán)限的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

1、對(duì)數(shù)據(jù)庫授權(quán)

postgresql 授權(quán)某個(gè)數(shù)據(jù)庫的權(quán)限給wang 賬號(hào) 使該賬號(hào) 只能操作指定DB 不能操作其他DB

alter user wang set default_transaction_read_only=on;
grant all on database test to wang;
grant select on all database test to wang;
grant select on all tables in schema public to wang;   // 起作用的是這句 要進(jìn)入數(shù)據(jù)庫test 操作,在那個(gè)db環(huán)境執(zhí)行就授哪個(gè)db的權(quán)

配置權(quán)限

ve=# grant all on schema public to foo ;
ve=# grant select,insert,update,delete on test to foo ;
ve=# grant select,insert,update,delete on public.test to foo ;

對(duì)表授權(quán)

撤銷授權(quán)

撤銷對(duì)數(shù)據(jù)庫授權(quán)

revoke all on database company from wang;   #撤銷用戶wang對(duì)數(shù)據(jù)庫company 的所有權(quán)限
revoke select on all tables in schema public from wang; 

撤銷對(duì)表授權(quán)

對(duì)當(dāng)前庫中所有表去掉public的所有訪問權(quán)限,為了確保除了所有者之外的洽談?dòng)脩舨荒懿僮鬟@些表。

lyy=# revoke all on test1 from public;
REVOKE
lyy=# revoke all on test2 from public;
REVOKE

去掉對(duì)pg_class的訪問權(quán)限,為了確保yy用戶不能看到所有表名的列表。

lyy=# revoke all on pg_class from public;
REVOKE
lyy=# revoke all on pg_class from yy;
REVOKE

添加yy用戶對(duì)test1表的所屬關(guān)系,確保yy用戶對(duì)test1表有權(quán)限操作

lyy=# ALTER TABLE test1 OWNER TO yy; 
lyy=# \q

用戶管理

/* 賦給用戶表的所有權(quán)限 */
GRANT ALL ON tablename TO user; 
/* 賦給用戶數(shù)據(jù)庫的所有權(quán)限 */
GRANT ALL PRIVILEGES ON DATABASE dbname TO dbuser;

/* 撤銷用戶權(quán)限 */
REVOKE privileges ON tablename FROM user;

數(shù)據(jù)庫操作

/* 創(chuàng)建數(shù)據(jù)庫 */
create database dbname; 

/* 刪除數(shù)據(jù)庫 */
drop database dbname; 

表操作

/* 增加讓主鍵自增的權(quán)限 */
grant all on sequence tablename_keyname_seq to webuser;

 /* 重命名一個(gè)表 */
alter table [表名A] rename to [表名B]; 

/* 刪除一個(gè)表 */
drop table [表名]; 

/* 在已有的表里添加字段 */
alter table [表名] add column [字段名] [類型]; 

/* 刪除表中的字段 */
alter table [表名] drop column [字段名]; 

/* 重命名一個(gè)字段 */
alter table [表名] rename column [字段名A] to [字段名B]; 

/* 給一個(gè)字段設(shè)置缺省值 */
alter table [表名] alter column [字段名] set default [新的默認(rèn)值];

/* 去除缺省值 */
alter table [表名] alter column [字段名] drop default; 

/* 插入數(shù)據(jù) */
insert into 表名 ([字段名m],[字段名n],......) values ([列m的值],[列n的值],......); 

/* 修改數(shù)據(jù) */
update [表名] set [目標(biāo)字段名]=[目標(biāo)值] where ...; 

/* 刪除數(shù)據(jù) */
delete from [表名] where ...; 

/* 刪除表 */
delete from [表名];

/* 查詢 */
SELECT * FROM dbname WHERE ...;

/* 創(chuàng)建表 */
create table (
  [字段名1] [類型1] primary key,

參考

創(chuàng)建用戶和數(shù)據(jù)庫

創(chuàng)建用戶

postgres=# create user username with password '****';

創(chuàng)建數(shù)據(jù)庫

postgres=# create database dbtest owner username; -- 創(chuàng)建數(shù)據(jù)庫指定所屬者

將數(shù)據(jù)庫得權(quán)限,全部賦給某個(gè)用戶

postgres=# grant all on database dbtest to username; -- 將dbtest所有權(quán)限賦值給username

導(dǎo)入整個(gè)數(shù)據(jù)庫

psql -U username databasename < /data/dum.sql -- 用戶名和數(shù)據(jù)庫名

常見報(bào)錯(cuò) :

1、切換yy用戶失敗

lyy=# \c - yy
FATAL: Peer authentication failed for user "yy"
Previous connection kept

2、用戶yy連接lyyku會(huì)報(bào)錯(cuò)

psql -E -U yy -d lyy
Password for user yy:
psql: FATAL: permission denied for database "lyy"
DETAIL: User does not have CONNECT privilege.

原因 :沒有connect權(quán)限,那么就授予用戶yy對(duì)數(shù)據(jù)庫lyy的訪問權(quán)限

解決辦法 :

#grant connect on database lyy to yy; 

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。

相關(guān)文章

最新評(píng)論

安阳市| 喀喇| 临沧市| 六枝特区| 漾濞| 垣曲县| 公安县| 淳化县| 黑河市| 巩义市| 奉贤区| 东丰县| 镇安县| 榆树市| 通城县| 内丘县| 汉中市| 安阳市| 西乌珠穆沁旗| 吉安县| 广丰县| 鹤岗市| 阿坝县| 呈贡县| 赤城县| 宜城市| 游戏| 叙永县| 昌宁县| 松滋市| 胶州市| 汤阴县| 藁城市| 石阡县| 和龙市| 南郑县| 宕昌县| 宿松县| 额济纳旗| 枣强县| 仪征市|