1.CREATE ROLE创建的用户默认不带LOGIN属性,而CREATE USER创建的用户默认带有LOGIN属性,如下:
postgres=# CREATE ROLE pg_test_user_1; /*默认不带LOGIN属性*/ CREATE ROLE postgres= CREATE USER pg_test_user_2; /*默认具有LOGIN属性*/ CREATE ROLE postgres= \du List of roles Role name | Attributes | Member of ----------------+--------------+----------- pg_test_user_1 | Cannot login | {} pg_test_user_2 | | {} postgres | Superuser | {} : Create role : Create DB postgres=#
CREATE ROLE pg_test_user_3 CREATEDB; /*具有创建数据库的属性*/
CREATE ROLE
postgres= \du
List of roles
Role name | Attributes | Member of
----------------+--------------+-----------
pg_test_user_1 | Cannot login | {}
pg_test_user_2 | | {}
pg_test_user_3 | Create DB | {}
: Cannot login
postgres | Superuser | {}
: Create role
: Create DB
postgres= CREATE ROLE pg_test_user_4 CREATEDB PASSWORD '123456'; /*具有创建数据库及带有密码登陆的属性 */
CREATE ROLE
postgres= \du
List of roles
Role name | Attributes | Member of
----------------+--------------+-----------
pg_test_user_1 | Cannot login | {}
pg_test_user_2 | | {}
pg_test_user_3 | Create DB | {}
: Cannot login
pg_test_user_4 | Create DB | {}
: Cannot login
postgres | Superuser | {}
: Create role
: Create DB
postgres= 3.给已存在用户赋予各种权限
使用ALTER ROLE即可。
\du
List of roles
Role name | Attributes | Member of
----------------+--------------+-----------
pg_test_user_3 | Create DB | {}
: Cannot login
pg_test_user_4 | Create DB | {}
: Cannot login
postgres | Superuser | {}
: Create role
: Create DB
postgres= ALTER ROLE pg_test_user_3 WITH LOGIN; /*赋予登录权限*/
ALTER ROLE
postgres= \du
List of roles
Role name | Attributes | Member of
----------------+--------------+-----------
pg_test_user_3 | Create DB | {}
pg_test_user_4 | Create DB | {}
: Cannot login
postgres | Superuser | {}
: Create role
: Create DB
postgres= ALTER ROLE pg_test_user_4 WITH CREATEROLE;/*赋予创建角色的权限*/
ALTER ROLE
postgres= \du
List of roles
Role name | Attributes | Member of
----------------+--------------+-----------
pg_test_user_3 | Create DB | {}
pg_test_user_4 | Create role | {}
: Create DB
: Cannot login
postgres | Superuser | {}
: Create role
: Create DB
postgres= ALTER ROLE pg_test_user_4 WITH PASSWORD '654321';/*修改密码*/
ALTER ROLE
postgres= ALTER ROLE pg_test_user_4 VALID UNTIL 'JUL 7 14:00:00 2012 +8'; /*设置角色的有效期*
ALTER ROLE
相关文章
项目需要,有个数据需要导入,拿到手一开始以为是mysql,结果...
本文小编为大家详细介绍“怎么查看PostgreSQL数据库中所有表...
错误现象问题原因这是在远程连接时pg_hba.conf文件没有配置正...
因本地资源有限,在公共测试环境搭建了PGsql环境,从数据库本...
wamp 环境 这个提示就是说你的版本低于10了。
先打印ph...
psycopg2.OperationalError: SSL SYSCALL error: EOF detect...