当前位置:网站首页>Use the PostgreSQL GRANT command to modify permissions on various database objects
Use the PostgreSQL GRANT command to modify permissions on various database objects
2022-07-29 21:38:00 【Wu Xin】
在PostgreSQL中,A user must have LOGIN权限to log into the database.然而,Explicit permissions must be assigned to perform database operations,Include selection table、列和记录.
PostgreSQL的GRANTQueries allow you to modify a user's permissions on database objects,如表、列、视图、函数、架构等等.
This tutorial will guide you to use itPostgreSQL GRANTcommands to modify permissions on various database objects.
基本用法
GRANT命令的基本语法是
GRANT privilege(s) ON object(s) TO user
复制代码在上面的语法中,You can specify one or more permissions to grant users permissions on specified objects.
To set all permissions on an object,可以使用ALL关键字.
Some of the permissions you can specify to grant on an object include.
- SELECT
- INSERT
- 更新
- DELETE
- 创建
- 连接
- 触发器
- TRUNCATE
- 引用
- 执行
接下来,You specify the database object and user to grant this set of permissions.
Grant statement example
让我们看一下如何在PostgreSQL数据库中使用GRANT查询的几个例子.
首先,Create a local user without permissions.要做到这一点,Make sure you are logged in as an admin user.
psql -U postgres
CREATE ROLE mods LOGIN PASSWORD 'hello';
复制代码在下一步,Create a sample database and tables,We will use it to illustratePostgreSQL的权限.
Below is an example query.
DROP DATABASE IF EXISTS privs;
CREATE DATABASE privs;
\c privs;
CREATE TABLE modify (id SERIAL, username VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, amount INT, PRIMARY KEY(id));
复制代码最后,退出Postgres用户,Log in as the user we just created above.在上面的例子中,使用以下命令.
psql -U mods -d privs;
复制代码例1
如果你试图从privs数据库的modifySelect a value from the table,You will get a permission denied error.
比如说
privs=> select * from modify;
ERROR: permission denied for table modify
复制代码You can pass grantmodsUser all rights or increase select rights to solve this error.
要做到这一点,请以Postgres用户的身份登录.
psql -U postgres -d privs;
GRANT SELECT ON modify TO mods;
复制代码这允许mods用户从privs数据库的modifySelect an item from the table.
一旦你运行select语句,You should get the following result.
privs=# SELECT * FROM modify;
id | username | email | amount
----+----------+-------+--------
(0 rows)
复制代码例2
You can also specify multiple permissions at once.例如,要指定SELECT、INSERT、DELETE和TRUNCATE的权限,使用命令.
GRANT SELECT, INSERT, DELETE, TRUNCATE ON modify TO mods;
复制代码例3
To grant all permissions to a user,Please set permissions to ALL,As shown in the command example below.
GRANT ALL ON modify TO mods;
复制代码例4
在上面的所有例子中,We only assigned permissions to a user on a specific table.If you want to grant permissions on all tables of the specified schema,我们可以使用命令.
GRANT SELECT, INSERT, DELETE, TRUNCATE ON ALL TABLES IN SCHEMA "privs" TO mods;
复制代码例5
You can also assign a connection permissionGRANTto a specific user,Get him into a specific database.查询方式是
GRANT CONNECT ON DATABASE privs TO mods;
复制代码To revoke all permissions granted to a user,可以使用REVOKE查询.
REVOKE SELECT, INSERT, DELETE, TRUNCATE ON modify FROM mods;
复制代码结束
as this guide shows,PostgreSQL允许你使用GRANT和REVOKEcommand to modify user permissions on database objects.
边栏推荐
- Hyaluronic acid-siRNA透明质酸修饰核糖核酸|peptide–siRNA 多肽偶连RNA/DNA核酸(齐岳PNA修饰物)
- mos管闩锁效应理解学习
- PEG-siRNA-PCL|siRNA-PEG-LHRH|MPEG-siRNA 甲氧基聚乙二醇修饰核酸
- GalNAc-siRNA甘露糖/半乳糖修饰脱氧核糖核酸|siRNA-S-S-DSPE(RNA修饰技术介绍)
- OAuth,JWT ,OIDC你们搞得我好乱啊
- conda virtual environment | install and list problems
- LeetCode--单链表--146.LRU缓存
- 如何进入董事会:给CIO的十条建议
- QT安装、创建项目与调试,在VS中的使用:手把手教程
- 探索创客教育在线管理实施体系
猜你喜欢

核壳二氧化钛纳米颗粒修饰DNA|二氢杨梅素修饰DNA药物|相关介绍

LeetCode 0144. 二叉树的前序遍历:二叉树必会题

博世集团启动量子数字孪生计划

Cobaltstrike and BurpSuite desktop shortcut configuration

怎么实现您的个人知识库?

The difference between analog, digital and switching

There is a fee for the picture bed software. Forget it, I wrote an open source free one.

促进二十一世纪创客教育的新发展

一线技术人应该关注的四种思维能力

The demand for VR live broadcast marketing is increasing, and the data module is paving the way for us
随机推荐
[ACTF2020 Freshman Competition]Exec 1
ALBERT: A Lite BERT for Self-supervised Learning of Language Representations
378. The Kth Smallest Element in an Ordered Matrix
In the past six months, I have done those things about the automatic return of the transaction link...
JS实现百叶窗特效
从专业角度分析国内创客教育发展
尿素偶联Urea-siRNA Conjugates|Cyclodextrin-siRNA-β-CD环糊精修饰RNA核酸(解析说明)
Dry goods!Cooperative Balance in Federated Learning
分布式限流 redission RRateLimiter 的使用及原理
LOG4J 学习
The difference between uri and url is simple to understand (what is the difference between uri and url)
LeetCode 593 有效的正方形[数学] HERODING的LeetCode之路
五个供应商销售谈判策略的识别以及应对它们的方法
分析少年派2中的Crypto
LeetCode 0593. 有效的正方形
断言+异常处理类,代码更简洁了
基于PaddleSpeech搭建个人语音听写服务
Briefly talk about K-means clustering
Writing Elegant Kotlin Code: Talk About What I Think "Kotlinic"
VR直播营销需求增加,数据模块为我们铺路