CREATE ROLE
Defines a new database role (user or group).
Synopsis
CREATE ROLE <name> [[WITH] <option> [ ... ]]
where option can be:
SUPERUSER | NOSUPERUSER
| CREATEDB | NOCREATEDB
| CREATEROLE | NOCREATEROLE
| CREATEUSER | NOCREATEUSER
| CREATEEXTTABLE | NOCREATEEXTTABLE [ ( <attribute>='<value>' [, ...] ) ]
| INHERIT | NOINHERIT
| LOGIN | NOLOGIN
| REPLICATION | NOREPLICATION
| CONNECTION LIMIT <connlimit>
| [ ENCRYPTED | UNENCRYPTED ] PASSWORD '<password>'
| VALID UNTIL '<timestamp>'
| IN ROLE <rolename> [, ...]
| ROLE <rolename> [, ...]
| ADMIN <rolename> [, ...]
| USER <rolename> [, ...]
| RESOURCE QUEUE <queue_name>
| RESOURCE GROUP <group_name>
| [ DENY <deny_point> ]
| [ DENY BETWEEN <deny_point> AND <deny_point>]
where attribute and value are:
type='readable'|'writable'
protocol='gpfdist'|'gpfdists'|'http'
Description
CREATE ROLE adds a new role to a Greengage DB system.
A role is an entity that can own database objects and have database privileges.
A role can be considered a user, a group, or both depending on how it is used.
You must have the CREATEROLE privilege or be a database superuser to use this command.
Note that roles are defined at the system level and are valid for all databases in your Greengage DB system.
Parameters
| Parameter | Description |
|---|---|
name |
The name of the new role |
SUPERUSER |
If |
CREATEDB |
If |
CREATEROLE |
If |
CREATEUSER |
These clauses are obsolete but still accepted, spellings of |
CREATEEXTTABLE |
If |
INHERIT |
If specified, |
LOGIN |
If specified, |
REPLICATION |
These clauses determine whether a role is allowed to initiate streaming replication or put the system in and out of backup mode.
A role having the |
CONNECTION LIMIT <connlimit> |
The maximum number of concurrent connections this role can make.
The default of |
PASSWORD '<password>' |
Sets the user password for roles with the |
VALID UNTIL '<timestamp>' |
The |
IN ROLE <rolename> |
Adds the new role as a member of the named roles.
Note that there is no option to add the new role as an administrator; use a separate |
ROLE <rolename> |
Adds the named roles as members of this role, making this new role a group |
ADMIN <rolename> |
The |
USER <rolename> |
The |
RESOURCE GROUP <group_name> |
The name of the resource group to assign to the new role.
The role will be subject to the concurrent transaction, memory, and CPU limits configured for the resource group.
You can assign a single resource group to one or more roles.
If you do not specify a resource group for a new role, the role is automatically assigned the default resource group for the role’s capability, |
RESOURCE QUEUE <queue_name> |
The name of the resource queue to which the new user-level role is to be assigned.
Only roles with the |
DENY <deny_point> |
The
The two parts of the
For
The
For example:
|
Notes
The preferred way to add and remove role members (manage groups) is to use GRANT and REVOKE.
The VALID UNTIL clause defines an expiration time for a password only, not for the role.
The expiration time is not enforced when logging in using a non-password-based authentication method.
The INHERIT attribute governs inheritance of grantable privileges (access privileges for database objects and role memberships).
It does not apply to the special role attributes set by CREATE ROLE and ALTER ROLE.
For example, being a member of a role with the CREATEDB privilege does not immediately grant the ability to create databases, even if INHERIT is set.
These privileges and attributes are never inherited: SUPERUSER, CREATEDB, CREATEROLE, CREATEEXTTABLE, LOGIN, RESOURCE GROUP, and RESOURCE QUEUE.
The attributes must be set on each user-level role.
The INHERIT attribute is the default for reasons of backwards compatibility.
However, NOINHERIT provides a closer match to the semantics specified in the SQL standard.
Be careful with the CREATEROLE privilege.
There is no concept of inheritance for the privileges of a CREATEROLE role.
That means that even if a role does not have a certain privilege but is allowed to create other roles, it can easily create another role with different privileges than its own (except for creating roles with superuser privileges).
For example, if a role has the CREATEROLE privilege but not the CREATEDB privilege, it can create a new role with the CREATEDB privilege.
Therefore, regard roles that have the CREATEROLE privilege as almost-superuser roles.
The CONNECTION LIMIT option is never enforced for superusers.
Caution must be exercised when specifying an unencrypted password with this command.
The password will be transmitted to the server in clear text, and it might also be logged in the client’s command history or the server log.
The client program createuser, however, transmits the password encrypted.
Also, psql contains a command \password that can be used to safely change the password later.
Examples
Create a role that can log in, but do not give it a password:
CREATE ROLE jonathan LOGIN;
Create a role that belongs to a resource queue:
CREATE ROLE jonathan LOGIN RESOURCE QUEUE poweruser;
Create a role with a password that is valid until the end of 2026 (CREATE USER is the same as CREATE ROLE except that it implies LOGIN):
CREATE USER joelle WITH PASSWORD 'jw8s0F4' VALID UNTIL '2027-01-01';
Create a role that can create databases and manage other roles:
CREATE ROLE admin WITH CREATEDB CREATEROLE;
Create a role that does not allow login access on Sundays:
CREATE ROLE user3 DENY DAY 'Sunday';
Create a role that can create readable and writable external tables of type gpfdist:
CREATE ROLE jan WITH CREATEEXTTABLE (type = 'readable', protocol = 'gpfdist')
CREATEEXTTABLE (type = 'writable', protocol = 'gpfdist');
Create a role, assigning a resource group:
CREATE ROLE bill RESOURCE GROUP rg_light;
Compatibility
The SQL standard defines the concepts of users and roles, but it regards them as distinct concepts and leaves all commands defining users to be specified by the database implementation. In Greengage DB, users and roles are unified into a single type of object. Roles therefore have many more optional attributes than they do in the standard.
CREATE ROLE is in the SQL standard, but the standard only requires the syntax:
CREATE ROLE <name> [WITH ADMIN <rolename>]
Allowing multiple initial administrators, and all the other options of CREATE ROLE, are Greengage DB extensions.
The behavior specified by the SQL standard is most closely approximated by giving users the NOINHERIT attribute, while roles are given the INHERIT attribute.