关于 SEQUENCE 的 USAGE | SELECT | UPDATE 权限实例

2024-01-27 23:28

本文主要是介绍关于 SEQUENCE 的 USAGE | SELECT | UPDATE 权限实例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

  • 结论:
  • 查看 SEQUENCE 相关的权限
  • 实例

结论:

usage:  对应 nextval 执行权限
select: 对应 select * from <sequence_name>; 执行权限
update: 对应 setval 执行权限

查看 SEQUENCE 相关的权限

GRANT { { USAGE | SELECT | UPDATE }[, ...] | ALL [ PRIVILEGES ] }ON { SEQUENCE sequence_name [, ...]| ALL SEQUENCES IN SCHEMA schema_name [, ...] }TO role_specification [, ...] [ WITH GRANT OPTION ]

实例

psql
(postgres)test3=# create sequence test_id_seq;
CREATE SEQUENCE
(postgres)test3=# create user test with password 'test';
CREATE ROLE
(postgres)test3=# \du test List of rolesRole name | Attributes | Member of 
-----------+------------+-----------test   |            | {}(postgres)test3=# \c - test 
You are now connected to database "test3" as user "test".
(postgres)test3=> \dp+ test_id_seqAccess privilegesSchema |    Name     |   Type   | Access privileges | Column privileges | Policies 
--------+-------------+----------+-------------------+-------------------+----------public | test_id_seq | sequence |                   |                   | 
(1 row)-- 默认 新建的用户对序列无 usage/select/update 权限
(postgres)test3=> select * from test_id_seq; 
ERROR:  permission denied for sequence test_id_seq
(postgres)test3=> 
(postgres)test3=> \c - postgres 
You are now connected to database "test3" as user "postgres".
(postgres)test3=# grant select on SEQUENCE test_id_seq to test ;
GRANT
(postgres)test3=# \dp+ test_id_seqAccess privilegesSchema |    Name     |   Type   |  Access privileges  | Column privileges | Policies 
--------+-------------+----------+---------------------+-------------------+----------public | test_id_seq | sequence | postgres=rwU/postgres+|                   | |             |          | test=r/postgres   |                   | 
(1 row)
-- select 对应的 select * from  <sequence_name>; 
(postgres)test3=# 
(postgres)test3=# \c - test 
You are now connected to database "test3" as user "test".
(postgres)test3=> select * from test_id_seq ;last_value | log_cnt | is_called 
------------+---------+-----------75 |       8 | t
(1 row)(postgres)test3=> select nextval('test_id_seq');
ERROR:  permission denied for sequence test_id_seq
(postgres)test3=> 
(postgres)test3=> 
(postgres)test3=> select setval('test_id_seq',10,false);
ERROR:  permission denied for sequence test_id_seq
(postgres)test3=> -- usage 对应的是 nextval 执行权限
(postgres)test3=> \c - postgres
You are now connected to database "test3" as user "postgres".
(postgres)test3=# grant usage on SEQUENCE test_id_seq to test ;
GRANT
(postgres)test3=# \c - test 
You are now connected to database "test3" as user "test".
(postgres)test3=> select setval('test_id_seq',10,false);
ERROR:  permission denied for sequence test_id_seq
(postgres)test3=> select nextval('test_id_seq');nextval 
---------76
(1 row)(postgres)test3=> select nextval('test_id_seq');nextval 
---------77
(1 row)-- update 对应的是 setval 权限
(postgres)test3=> \c - postgres 
You are now connected to database "test3" as user "postgres".
(postgres)test3=# grant update on SEQUENCE test_id_seq  to test ;
GRANT
(postgres)test3=# \c - test 
You are now connected to database "test3" as user "test".
(postgres)test3=> select * from test_id_seq;last_value | log_cnt | is_called 
------------+---------+-----------77 |      31 | t
(1 row)(postgres)test3=> select nextval('test_id_seq');nextval 
---------78
(1 row)(postgres)test3=> select nextval('test_id_seq');nextval 
---------79
(1 row)(postgres)test3=> select setval('test_id_seq',100,false);setval 
--------100
(1 row)(postgres)test3=> select nextval('test_id_seq');nextval 
---------100
(1 row)
(postgres)test3=> exit

这篇关于关于 SEQUENCE 的 USAGE | SELECT | UPDATE 权限实例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/651804

相关文章

Go异常处理、泛型和文件操作实例代码

《Go异常处理、泛型和文件操作实例代码》Go语言的异常处理机制与传统的面向对象语言(如Java、C#)所使用的try-catch结构有所不同,它采用了自己独特的设计理念和方法,:本文主要介绍Go异... 目录一:异常处理常见的异常处理向上抛中断程序恢复程序二:泛型泛型函数泛型结构体泛型切片泛型 map三:文

kingbase修改权限实现方式

《kingbase修改权限实现方式》该文章详细介绍了如何在数据库中创建用户并赋予其相应的权限,包括创建用户、回收默认权限、创建数据库、赋权数据库权限、创建只读用户以及回收权限等步骤... 目录前言使用步骤总结前言创建用户后对数据库对象的读写权限进行修改使用步骤1、创建用户create user cs

springboot+mybatis一对多查询+懒加载实例

《springboot+mybatis一对多查询+懒加载实例》文章介绍了如何在SpringBoot和MyBatis中实现一对多查询的懒加载,通过配置MyBatis的`fetchType`属性,可以全局... 目录springboot+myBATis一对多查询+懒加载parent相关代码child 相关代码懒

C++中的解释器模式实例详解

《C++中的解释器模式实例详解》这篇文章总结了C++标准库中的算法分类,还介绍了sort和stable_sort的区别,以及remove和erase的结合使用,结合实例代码给大家介绍的非常详细,感兴趣... 目录1、非修改序列算法1.1 find 和 find_if1.2 count 和 count_if1

MySQL中如何求平均值常见实例(AVG函数详解)

《MySQL中如何求平均值常见实例(AVG函数详解)》MySQLavg()是一个聚合函数,用于返回各种记录中表达式的平均值,:本文主要介绍MySQL中用AVG函数如何求平均值的相关资料,文中通过代... 目录前言一、基本语法二、示例讲解1. 计算全表平均分2. 计算某门课程的平均分(例如:Math)三、结合

Linux下利用select实现串口数据读取过程

《Linux下利用select实现串口数据读取过程》文章介绍Linux中使用select、poll或epoll实现串口数据读取,通过I/O多路复用机制在数据到达时触发读取,避免持续轮询,示例代码展示设... 目录示例代码(使用select实现)代码解释总结在 linux 系统里,我们可以借助 select、

PyQt6 键盘事件处理的实现及实例代码

《PyQt6键盘事件处理的实现及实例代码》本文主要介绍了PyQt6键盘事件处理的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起... 目录一、键盘事件处理详解1、核心事件处理器2、事件对象 QKeyEvent3、修饰键处理(1)、修饰键类

SpringBoot AspectJ切面配合自定义注解实现权限校验的示例详解

《SpringBootAspectJ切面配合自定义注解实现权限校验的示例详解》本文章介绍了如何通过创建自定义的权限校验注解,配合AspectJ切面拦截注解实现权限校验,本文结合实例代码给大家介绍的非... 目录1. 创建权限校验注解2. 创建ASPectJ切面拦截注解校验权限3. 用法示例A. 参考文章本文

SpringBoot+RustFS 实现文件切片极速上传的实例代码

《SpringBoot+RustFS实现文件切片极速上传的实例代码》本文介绍利用SpringBoot和RustFS构建高性能文件切片上传系统,实现大文件秒传、断点续传和分片上传等功能,具有一定的参考... 目录一、为什么选择 RustFS + SpringBoot?二、环境准备与部署2.1 安装 RustF

MySQL中On duplicate key update的实现示例

《MySQL中Onduplicatekeyupdate的实现示例》ONDUPLICATEKEYUPDATE是一种MySQL的语法,它在插入新数据时,如果遇到唯一键冲突,则会执行更新操作,而不是抛... 目录1/ ON DUPLICATE KEY UPDATE的简介2/ ON DUPLICATE KEY UP