user permissions to create a database
(1) Check to confirm that Superuser Highgo has the right to create a database, and that normal user A does not have permission to create a database
Highgo=#\du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
A | | {}
Highgo | Superuser, create role, create DB, Replication | {}
highgo= #select Current_User;
Current_User
--------------
Highgo
(1row)
highgo= #create database highgo_t;
CreateDatabase
Highgo=#\c Highgo A
Youare now connected to database "Highgo" as User "a".
Highgo=>create database a_t;
Error: Insufficient permissions to create database
Highgo=>
(2) Giving ordinary User a permission to create a database, but not giving superuser privileges, user A can create a database
highgo= #alter User A createdb;
Alterrole
Highgo=#\du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
A | Create DB | {}
Highgo | Superuser, create role, create DB, Replication | {}
Highgo=#\c Highgo A
Youare now connected to database "Highgo" as User "a".
Highgo=>create database a_t;
CreateDatabase
Highgo=>\l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access Privileges
-----------+--------+----------+------------+------------+-------------------
a_t | A | UTF8 | Zh_cn.utf8 | Zh_cn.utf8 |
Highgo | Highgo | UTF8 | Zh_cn.utf8 |zh_cn.utf8 | =tc/highgo +
| | | | | Highgo=ctc/highgo
highgo_t | Highgo | UTF8 | Zh_cn.utf8 |zh_cn.utf8 |
Template0 | Highgo | UTF8 | Zh_cn.utf8 | Zh_cn.utf8 | =c/highgo +
| | | | | Highgo=ctc/highgo
template1 | Highgo | UTF8 | Zh_cn.utf8 | Zh_cn.utf8 | =c/highgo +
| | | | | Highgo=ctc/highgo
(5rows)
(3) gives User a superuser the right to create a database, but does not give it a separate permission, at which point User A can create a database
highgo= #alter User A nocreatedb;
Alterrole
Highgo=#\du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
A | | {}
Highgo | Superuser, create role, create DB, Replication | {}
highgo= #alter User A superuser;
Alterrole
Highgo=#\du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
A | Superuser | {}
Highgo | Superuser, create role, create DB, Replication | {}
Highgo=#\c Highgo A
Youare now connected to database "Highgo" as User "a".
highgo= #create database a_tb;
CreateDatabase
Highgo=#\l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access Privileges
-----------+--------+----------+------------+------------+-------------------
a_t | A | UTF8 | Zh_cn.utf8 | Zh_cn.utf8 |
A_TB | A | UTF8 | Zh_cn.utf8 | Zh_cn.utf8 |
Highgo | Highgo | UTF8 | Zh_cn.utf8 |zh_cn.utf8 | =tc/highgo +
| | | | | Highgo=ctc/highgo
highgo_t | Highgo | UTF8 | Zh_cn.utf8 | Zh_cn.utf8 |
Template0 | Highgo | UTF8 | Zh_cn.utf8 | Zh_cn.utf8 | =c/highgo +
| | | | | Highgo=ctc/highgo
template1 | Highgo | UTF8 | Zh_cn.utf8 | Zh_cn.utf8 | =c/highgo +
| | | | | Highgo=ctc/highgo
(6rows)