postgresql中DROP OWNED BY user_name对普通用户和只读用户的区别
1.首先建立一个普通用户,普通用户建立schema,并在schema下建表
DROP OWNED BY user_name;
postgres=# create user test with password 'test@123';
CREATE ROLE
postgres=# create schema test authorization test;
CREATE SCHEMA
postgres=# grant select,insert,update,delete on all tables in schema test to test;
GRANT
postgres=# \duList of rolesRole name | Attributes | Member of
--------------------+------------------------------------------------------------+-----------TEST_Lord_South_Mg | Superuser | {}athena_postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}athena_repluser | Replication | {}sdfmqry | | {}tbase | Superuser, Create role, Create DB | {}tbaseadmin | Create role, Create DB | {}test | | {}
postgres=# \dnList of schemasName | Owner
-----------+-----------------pglogical | tbasepublic | athena_postgrestest | test
(3 rows)postgres=# create table test.a(a int);
CREATE TABLE
postgres=# \d a
WARNING: unrecognized node type: 360Table "test.a"Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------a | integer | | |
2.执行drop语句
postgres=# DROP OWNED BY test;
DROP OWNED
3.查询表和schema,表和schema都被删除
postgres=# \d test.a
Did not find any relation named "test.a".
postgres=# \dnList of schemasName | Owner
-----------+-----------------pglogical | tbasepublic | athena_postgres
(2 rows)
4.建立一个只读用户
ostgres=# create user sdfmqry with password 'sdfmqry@123';
CREATE ROLE
postgres=# grant select on all tables in schema public to sdfmqry ;
GRANT
执行drop语句
postgres=# DROP OWNED BY sdfmqry;
DROP OWNED
postgres=# drop user sdfmqry ;
DROP ROLE
postgres=# \d test.a Table "test.a"Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------a | integer | | | postgres=# \duList of rolesRole name | Attributes | Member of
--------------------+------------------------------------------------------------+-----------TEST_Lord_South_Mg | Superuser | {}athena_postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}athena_repluser | Replication | {}tbase | Superuser, Create role, Create DB | {}tbaseadmin | Create role, Create DB | {}test | | {}
结论:
DROP OWNED BY readonly;
应得结论:
1.普通用户(有对象,如表)会删除普通用户的所有对象
2..只读用户(无对象,只有权限)只读用户无影响
对普通用户还是 慎用
postgresql中DROP OWNED BY user_name对普通用户和只读用户的区别相关推荐
- Postgresql杂谈 04—Postgresql中的五种常规索引
一.索引的分类 Postgresql中索引一共分为5种,每一种都有它合适的应用场景,我们在使用时要根据不同业务的特点,选择合适的索引,这样才能加快sql语句的查询效率.下面,我们将就每种不同的索引,介 ...
- Postgresql中如何正确删除role
关于删除role的一些理论 首先,删除用户不能使用DROP ROLE - CASCADE,不能级联删除用户.也就是不能删除依赖的对象. 因为角色可以拥有数据库对象,并且可以拥有访问其他数据库对象的权限 ...
- 在 PostgreSQL 中使用码农很忙 IP 地址数据库
在下载到码农很忙 IP 地址数据库后,我们可以将其存储在 PostgreSQL 数据库中,并在需要查询某个 IP 对应的位置数据时,通过 SQL 语句获取正确的结果.这是一种很便捷的使用方式,并且在增 ...
- PostgreSQL中的“use database_name”命令
本文翻译自:"use database_name" command in PostgreSQL I am beginner to PostgreSQL. 我是PostgreSQL的 ...
- Postgresql杂谈 10—Postgresql中的分区表
一.关于分区表 表分区是在大数据优化中的一种常见的分表方案,通过将大数据按照一定的规则(最常见的是按照时间)进行分表处理,将逻辑上的一个大表分割成物理上的几块表,插入数据时,数据会自动插入到不同的分区 ...
- PostgreSQL 中的单引号与双引号
PostgreSQL 中的单引号与双引号 在pg中的sql,单引号用来标识实际的值,双引号用来标识表名(table name)或列名(column name)等数据库中存在的值. 如,执行一句quer ...
- Postgresql杂谈 16—Postgresql中的锁机制
今天,我们学习下Postgresql中的锁机制.锁是数据库事务的基础,通过锁才能保证数据库在并发时能够保证数据的安全和一致,才能够达到事务的一致性和隔离性.但是任何事物都有它的两面性,引入锁同样会增加 ...
- pg数据库json数据类型_科学网—如何使用PostgreSQL中的JSONB数据类型(PG JSON系列2) - 孙鹏的博文...
上一篇 使用PostgreSQL中的row_to_json()直接获得JSON(PG JSON系列1)主要针对现有的非json/jsonb类型如何输出json结果,这一篇主要写一下在数据库设计中直接使 ...
- PostgreSQL中的表锁
本文转自PostgreSQL中文社区,文章链接:https://www.modb.pro/db/26462 PostgreSQL的并发控制以**快照隔离(SI)为主,以两阶段锁定(2PL)**机制为辅 ...
- PostgreSQL中的分区表
PostgreSQL中的分区表 参考:https://www.xmmup.com/pgzhongdefenqubiao.html#PG_11xin_te_xing PostgreSQL分区的意思是把逻 ...
最新文章
- Android StageFrightMediaScanner源码解析
- 【Python】全网最新最全Pyecharts可视化教程(二):绘制好看的交互式地图教程
- Swift5关于根据一个frame得到最大X值和最大Y值
- 为 .net 生态贡献力量——制作并上传 nuget 包(内有独家彩蛋)
- 喝最烈的酒、挖最大的DONG——工具与技巧篇
- silverlight项目工作小结
- element中的table相关
- 「创作之秋」| 参赛成员- 获奖名单(参与奖)
- python语言程序设计基础笔记(三)计算机思维
- Java成神之路——技术栈
- billing block
- java mqc系统开源代码_android PDF阅读器(开源) 暴强哦
- v4l2架构专题模块handler分析 -- handler ctrl的注册2
- 一份简单的车辆环视全景系统实现
- 神经网络编程(python实现)
- SecureCRT和SecureFX用法
- ABAP - OO ALV基本实现步骤
- 汽车驾驶学习-驾驶技巧:倒车速成
- 【zlmediakit】windows cmake +vs 构建
- 如何用ijkplayer使用改变清晰度功能(切换码流)