当前位置:网站首页>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)最后是操作表中的某些字段的权限
边栏推荐
- R language uses lubridate package to process date and time data
- 什么是文本挖掘 ?「建议收藏」
- Go语言学习教程(十六)
- Pandora IOT development board learning (HAL Library) - Experiment 8 timer interrupt experiment (learning notes)
- Windows Oracle 开启远程连接 Windows Server Oracle 开启远程连接
- Web3.0时代来了,看天翼云存储资源盘活系统如何赋能新基建(下)
- 在线协作产品哪家强?微软 Loop 、Notion、FlowUs
- Low code practice of xtransfer, a cross-border payment platform: how to integrate with other medium-sized platforms is the core
- CF: B. almost Ternary Matrix [symétrie + règles de recherche + Construction + I am Construction Waste]
- R language Visual scatter plot graph, add labels to some data points in the graph, and always display all labels, even if they have too much overlap. Ggrep package helps
猜你喜欢
UDF implementation of Dameng database
2022最新中高级Android面试题目,【原理+实战+视频+源码】
跨境支付平台 XTransfer 的低代码实践:如何与其他中台融合是核心
5. Data access - entityframework integration
Oracle 中文排序 Oracle 中文字段排序
Oracle日期格式转换 to_date,to_char,to_timetamp 相互转换
Word finds red text word finds color font word finds highlighted formatted text
Thoroughly understand why network i/o is blocked?
数据库 逻辑处理功能
Word查找红色文字 Word查找颜色字体 Word查找突出格式文本
随机推荐
[performance test] jmeter+grafana+influxdb deployment practice
一朵云开启智慧交通新未来
Go语言 | 03 数组、指针、切片用法
golang通过指针for...range实现切片中元素的值的更改
Isprs2022/ cloud detection: cloud detection with boundary nets
Video fusion cloud platform easycvr adds multi-level grouping, which can flexibly manage access devices
c语言简便实现链表增删改查「建议收藏」
HiEngine:可媲美本地的云原生内存数据库引擎
R language uses lubridate package to process date and time data
Oracle Chinese sorting Oracle Chinese field sorting
详解SQL中Groupings Sets 语句的功能和底层实现逻辑
基于FPGA的超声波测距
一文读懂简单查询代价估算
Tupu software digital twin | visual management system based on BIM Technology
max31865模块RTD测温注意事项
Word finds red text word finds color font word finds highlighted formatted text
2022 latest Android interview written examination, an Android programmer's interview experience
中文版Postman?功能真心强大!
5年经验Android程序员面试27天,2022程序员进阶宝典
Debezium系列之:postgresql从偏移量加载正确的最后一次提交 LSN