当前位置:网站首页>PG基础篇--逻辑结构管理(用户及权限管理)
PG基础篇--逻辑结构管理(用户及权限管理)
2022-07-05 18:57:00 【51CTO】
用户与角色
在postgreSQL中,角色和用户是没有区别的,一个用户也是一个角色,可以把一个用户的权限赋予给另一个用户。用户和角色在整个数据库实例中是全局的,在同一个实例中的不同数据库中,看到的用户都是相同的。
在初始化数据库系统时有一个预定义的超级用户,这个用户的名称和初始化该数据库的操作系统用户名相同。
在pg中,用户和角色是没有区别的,除了create user默认创建出来的用户有login权限,create role创建出来的用户没有login权限之外,create rule与create user没有其他的区别。
如何创建用户
CREATE USER name [ [ WITH ] option [ ... ] ]
where option can be :
SUPERUSER | NOSUPERUSER #是否是超级用户
| CREATEDB | NOCREATEDB #是否具有create database权限
| CREATEROLE | NOCREATEROLE #是否具有创建其他角色的权限
| INHERIT | NOINHERIT #创建的用户如果拥有角色,是否自动拥有角色权限
| LOGIN | NOLOGIN #是否有LOGIN权限
| REPLICATION | NOREPLICATION #复制权限
| BYPASSRLS | NOBYPASSRLS
| CONNECTION LIMIT connlimit
| [ ENCRYPTED ] PASSWORD 'password' | PASSWORD NULL
| VALID UNTIL 'timestamp' #密码失效时间
| IN ROLE role_name [ , ... ]
| IN GROUP role_name [ , ... ]
| ROLE role_name [ , ... ]
| ADMIN role_name [ , ... ] #with admin option权限
| USER role_name [ , ... ]
| SYSID uid
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
权限管理
在pg中,每个数据库的逻辑结构对象都有一个所有者,任何数据库对象都是属于某个用户的,所有不用把对象的权限再赋予所有者,因为所有者默认就拥有所有的权限。所有者也隐式的拥有把操作该对象的权限赋予其他用户的权利
权限分类
创建用户时指定的权限
超级用户权限
创建数据库权限
是否有login权限
也可以通过alter role来修改
需要grant或revoke的权限
在数据库中创建schema权限
允许在指定数据库中创建临时表的权限
连接某个数据库的权限
在模式中创建数据库对象的权限
select、DML操作权限
序列查询,函数使用,触发器权限
指定表,索引到表空间的权限
role_name 指用户或者角色
some_privileges 指权限
database_object_type指数据库对象,如table、schema、sequence
grant select on table mytab to public;
pg没有DDL权限,是否创建表,是看在schema中是否具有create的权限。
权限总结
权限是按层次进行管理的
1)首先管理赋在用户特殊属性上的权限,如超级用户的权限,创建数据库的权限,创建用户的权限,LOGIN权限等。
2)然后是在数据库中创建模式的权限。
3)接着是在模式中创建数据库的对象的权限,创建表,索引等。
4)之后是查询表,向表中插入数据,更新表,删除表中的数据权限。
5)最后是操作表中的某些字段的权限
边栏推荐
- 集合处理的利器
- Mysql database indexing tutorial (super detailed)
- 100million single men and women supported an IPO with a valuation of 13billion
- 什么是文本挖掘 ?「建议收藏」
- 2022年阿里Android高级面试题分享,2022阿里手淘Android面试题目
- cf:B. Almost Ternary Matrix【对称 + 找规律 + 构造 + 我是构造垃圾】
- Low code practice of xtransfer, a cross-border payment platform: how to integrate with other medium-sized platforms is the core
- Word finds red text word finds color font word finds highlighted formatted text
- Isprs2022/ cloud detection: cloud detection with boundary nets
- Tianyi cloud understands enterprise level data security in this way
猜你喜欢
Summary of six points of MySQL optimization
Ultrasonic ranging based on FPGA
Go deep into the underlying C source code and explain the core design principles of redis
Oracle date format conversion to_ date,to_ char,to_ Timestamp mutual conversion
AI open2022 | overview of recommendation systems based on heterogeneous information networks: concepts, methods, applications and resources
5. 数据访问 - EntityFramework集成
Chinese postman? Really powerful!
Teach you to deal with JS reverse picture camouflage hand in hand
一朵云开启智慧交通新未来
Icml2022 | partial and asymmetric comparative learning of out of distribution detection in long tail recognition
随机推荐
输油管的布置数学建模matlab,输油管布置的数学模型
2022 latest intermediate and advanced Android interview questions, [principle + practice + Video + source code]
EMQX 5.0 正式发布:单集群支持 1 亿 MQTT 连接
数学分析_笔记_第9章:曲线积分与曲面积分
潘多拉 IOT 开发板学习(HAL 库)—— 实验8 定时器中断实验(学习笔记)
企业数字化转型之路,从这里开始
Word finds red text word finds color font word finds highlighted formatted text
Thoroughly understand why network i/o is blocked?
2022全网最全的腾讯后台自动化测试与持续部署实践【万字长文】
Optimization of middle alignment of loading style of device player in easycvr electronic map
Why can't Bi software do correlation analysis? Take you to analyze
Oracle故障处理:Ora-10873:file * needs to be either taken out of backup or media recovered
Oracle日期格式转换 to_date,to_char,to_timetamp 相互转换
集合处理的利器
UDF implementation of Dameng database
Golang through pointer for Range implements the change of the value of the element in the slice
面试官:Redis 过期删除策略和内存淘汰策略有什么区别?
AI金榜题名时,MLPerf榜单的份量究竟有多重?
Tupu software digital twin smart wind power system
The worse the AI performance, the higher the bonus? Doctor of New York University offered a reward for the task of making the big model perform poorly