创建新用户及设置密码:
highgo=# create user e login password 'highgo123';
CREATE ROLE
highgo=# create user f with password 'highgo123';
CREATE ROLE
highgo=# create user g password 'highgo123';
CREATE ROLE
[highgo@db ~]$ createuser e -P
Enter password for new role:
Enter it again:
Password:
[highgo@db ~]$
[highgo@db ~]$ dropuser e;
Password:
将用户设置为超级用户:
highgo=# alter user e with superuser;
ALTER ROLE
highgo=# alter user e superuser;
ALTER ROLE
创建用户时指定该用户为超级用户:
[highgo@db ~]$ createuser e -P -s
Enter password for new role:
Enter it again:
Password:
[highgo@db ~]$ psql -U e
Password for user e:
psql: 致命错误: 数据库 "e" 不存在
[highgo@db ~]$ psql -d highgo -U e
Password for user e:
psql (3.0.2)
Type "help" for help.
highgo=#
删除用户:
highgo=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
a | | {}
b | Superuser | {}
highgo | Superuser, Create role, Create DB, Replication | {}
t | | {}
test1 | | {}
test2 | | {}
highgo=# drop user a;
错误: 无法删除"a"因为有其它对象倚赖它
DETAIL: 模式 a的属主
highgo=# drop schema a;
DROP SCHEMA
highgo=# drop user a;
DROP ROLE
highgo=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
b | Superuser | {}
highgo | Superuser, Create role, Create DB, Replication | {}
t | | {}
test1
highgo=# create user e login password 'highgo123';
CREATE ROLE
highgo=# create user f with password 'highgo123';
CREATE ROLE
highgo=# create user g password 'highgo123';
CREATE ROLE
[highgo@db ~]$ createuser e -P
Enter password for new role:
Enter it again:
Password:
[highgo@db ~]$
[highgo@db ~]$ dropuser e;
Password:
将用户设置为超级用户:
highgo=# alter user e with superuser;
ALTER ROLE
highgo=# alter user e superuser;
ALTER ROLE
创建用户时指定该用户为超级用户:
[highgo@db ~]$ createuser e -P -s
Enter password for new role:
Enter it again:
Password:
[highgo@db ~]$ psql -U e
Password for user e:
psql: 致命错误: 数据库 "e" 不存在
[highgo@db ~]$ psql -d highgo -U e
Password for user e:
psql (3.0.2)
Type "help" for help.
highgo=#
删除用户:
highgo=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
a | | {}
b | Superuser | {}
highgo | Superuser, Create role, Create DB, Replication | {}
t | | {}
test1 | | {}
test2 | | {}
highgo=# drop user a;
错误: 无法删除"a"因为有其它对象倚赖它
DETAIL: 模式 a的属主
highgo=# drop schema a;
DROP SCHEMA
highgo=# drop user a;
DROP ROLE
highgo=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
b | Superuser | {}
highgo | Superuser, Create role, Create DB, Replication | {}
t | | {}
test1