关于 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

相关文章

Spring中@Lazy注解的使用技巧与实例解析

《Spring中@Lazy注解的使用技巧与实例解析》@Lazy注解在Spring框架中用于延迟Bean的初始化,优化应用启动性能,它不仅适用于@Bean和@Component,还可以用于注入点,通过将... 目录一、@Lazy注解的作用(一)延迟Bean的初始化(二)与@Autowired结合使用二、实例解

HTML5中下拉框<select>标签的属性和样式详解

《HTML5中下拉框<select>标签的属性和样式详解》在HTML5中,下拉框(select标签)作为表单的重要组成部分,为用户提供了一个从预定义选项中选择值的方式,本文将深入探讨select标签的... 在html5中,下拉框(<select>标签)作为表单的重要组成部分,为用户提供了一个从预定义选项中

Android 悬浮窗开发示例((动态权限请求 | 前台服务和通知 | 悬浮窗创建 )

《Android悬浮窗开发示例((动态权限请求|前台服务和通知|悬浮窗创建)》本文介绍了Android悬浮窗的实现效果,包括动态权限请求、前台服务和通知的使用,悬浮窗权限需要动态申请并引导... 目录一、悬浮窗 动态权限请求1、动态请求权限2、悬浮窗权限说明3、检查动态权限4、申请动态权限5、权限设置完毕后

前端原生js实现拖拽排课效果实例

《前端原生js实现拖拽排课效果实例》:本文主要介绍如何实现一个简单的课程表拖拽功能,通过HTML、CSS和JavaScript的配合,我们实现了课程项的拖拽、放置和显示功能,文中通过实例代码介绍的... 目录1. 效果展示2. 效果分析2.1 关键点2.2 实现方法3. 代码实现3.1 html部分3.2

在MySQL执行UPDATE语句时遇到的错误1175的解决方案

《在MySQL执行UPDATE语句时遇到的错误1175的解决方案》MySQL安全更新模式(SafeUpdateMode)限制了UPDATE和DELETE操作,要求使用WHERE子句时必须基于主键或索引... mysql 中遇到的 Error Code: 1175 是由于启用了 安全更新模式(Safe Upd

浅析如何使用Swagger生成带权限控制的API文档

《浅析如何使用Swagger生成带权限控制的API文档》当涉及到权限控制时,如何生成既安全又详细的API文档就成了一个关键问题,所以这篇文章小编就来和大家好好聊聊如何用Swagger来生成带有... 目录准备工作配置 Swagger权限控制给 API 加上权限注解查看文档注意事项在咱们的开发工作里,API

mysqld_multi在Linux服务器上运行多个MySQL实例

《mysqld_multi在Linux服务器上运行多个MySQL实例》在Linux系统上使用mysqld_multi来启动和管理多个MySQL实例是一种常见的做法,这种方式允许你在同一台机器上运行多个... 目录1. 安装mysql2. 配置文件示例配置文件3. 创建数据目录4. 启动和管理实例启动所有实例

Java function函数式接口的使用方法与实例

《Javafunction函数式接口的使用方法与实例》:本文主要介绍Javafunction函数式接口的使用方法与实例,函数式接口如一支未完成的诗篇,用Lambda表达式作韵脚,将代码的机械美感... 目录引言-当代码遇见诗性一、函数式接口的生物学解构1.1 函数式接口的基因密码1.2 六大核心接口的形态学

SQL Server使用SELECT INTO实现表备份的代码示例

《SQLServer使用SELECTINTO实现表备份的代码示例》在数据库管理过程中,有时我们需要对表进行备份,以防数据丢失或修改错误,在SQLServer中,可以使用SELECTINT... 在数据库管理过程中,有时我们需要对表进行备份,以防数据丢失或修改错误。在 SQL Server 中,可以使用 SE

java图像识别工具类(ImageRecognitionUtils)使用实例详解

《java图像识别工具类(ImageRecognitionUtils)使用实例详解》:本文主要介绍如何在Java中使用OpenCV进行图像识别,包括图像加载、预处理、分类、人脸检测和特征提取等步骤... 目录前言1. 图像识别的背景与作用2. 设计目标3. 项目依赖4. 设计与实现 ImageRecogni