Cloudberry Database manages database access using roles. Initially, there is one superuser role, the role associated with the OS user who initialized the database instance, usually gpadmin
. This user owns all of the Cloudberry Database files and OS processes, so it is important to reserve the gpadmin
role for system tasks only.
A role can be a user or a group. A user role can log into a database; that is, it has the LOGIN
attribute. A user or group role can become a member of a group.
Permissions can be granted to users or groups. Initially, only the gpadmin
role is able to create roles. You can add roles using the createuser
utility command, CREATE ROLE
SQL command, or the CREATE USER
SQL command. The CREATE USER
command is the same as the CREATE ROLE
command except that it automatically assigns the role the LOGIN
attribute.
Quick-start operations
You can follow the examples below to create users and roles.
Before moving on to the operations, make sure that you have installed Cloudberry Database by following Install a Single-Node Cloudberry Database.
Create a user using the CREATE USER command
-
Log into Cloudberry Database in Docker. Connect to the database as the
gpadmin
user.[gpadmin@mdw ~]$ psql
psql (14.4, server 14.4)
Type "help" for help.gpadmin=#
-
Create a user named
lily
using theCREATE USER
command, with a passwordchangeme
. After the creation, you need to enter the password to log in as the userlily
.gpadmin=# CREATE USER lily WITH PASSWORD 'changeme';
Output:
NOTICE: resource queue required -- using default resource queue "pg_default"
CREATE ROLE -
Verify that the user
lily
has been created.gpadmin=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
gpadmin | Superuser, Create role, Create DB, Replication | {}
lily | | {}
Create a user using the createuser utility command
-
Create a user named
lucy
using thecreateuser
utility command.gpadmin=# \q -- exit psql
[gpadmin@mdw ~]$ createuser --interactive lucy
You will be asked to choose whether the new role should be a superuser. Enter
y
to create a superuser.Shall the new role be a superuser? (y/n)
-
Connect to the database as the
gpadmin
user.[gpadmin@mdw ~]$ psql
psql (14.4, server 14.4)
Type "help" for help. -
Verify that the user
lucy
has been created.gpadmin=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
gpadmin | Superuser, Create role, Create DB, Replication | {}
lily | | {}
lucy | Superuser, Create role, Create DB | {}gpadmin=# \q -- exit psql