Define a new database role (user or group).
CREATE ROLE name [[WITH] option [ ... ]]
Where option can be:
SUPERUSER | NOSUPERUSER
| CREATEDB | NOCREATEDB
| CREATEROLE | NOCREATEROLE
| CREATEUSER | NOCREATEUSER
| CREATEEXTTABLE | NOCREATEEXTTABLE
[ ( attribute='value'[, ...] ) ]
where attributes and value are:
type='readable'|'writable'
protocol='gpfdist'|'http'
| 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 [, ...]
| SYSID uid [, ...]
| RESOURCE QUEUE queue_name
| RESOURCE GROUP group_name
| [ DENY deny_point ]
| [ DENY BETWEEN deny_point AND deny_point]
CREATE ROLE has added a new role to the YMatrix database system. A role is an entity that can own database objects and have database privileges. Depending on how the role is used, a role can be considered as a user, a group, or both. You must have CREATEROLE privilege or a database superuser to use this command.
Note that roles are defined at the system level and are valid for all databases in the YMatrix database system.
name
SUPERUSER
NOSUPERUSER
CREATEDB
NOCREATEDB
CREATEROLE
NOCREATEROLE
CREATEUSER
NOCREATEUSER
CREATEEXTTABLE
NOCREATEEXTTABLE
INHERIT
NOINHERIT
LOGIN
NOLOGIN
REPLICATION
NOREPLICATION
CONNECTION LIMIT connlimit
PASSWORD password
ENCRYPTED
UNENCRYPTED
VALID UNTIL 'timestamp'
IN ROLE rolename
ROLE rolename
ADMIN rolename
RESOURCE GROUP group_name
RESOURCE QUEUE queue_name
DENY deny_point
DENY BETWEEN deny_point AND deny_point
DAY day [ TIME 'time' ]
{'Sunday' | 'Monday' | 'Tuesday' |'Wednesday' | 'Thursday' | 'Friday' | 'Saturday' | 0-6 }
{ 00-23 : 00-59 | 01-12 : 00-59 { AM | PM }}
DENY BETWEEN deny_point AND deny_point
## Note
The preferred method to add and delete role members (administrative groups) is to use GRANT and REVOKE.The VALID UNTIL clause defines expiration time only for passwords and not roles. When logging in with a non-password-based authentication method, expiration time is not forced.
The INHERIT attribute controls inheritance that can be granted (access privileges for database objects and role members). It does not apply to special role properties set by CREATE ROLE and ALTER ROLE. For example, even if INHERIT is set, role members with CREATEDB privileges do not immediately grant the ability to create a database. These privileges/attributes are never inherited: SUPERUSER, CREATEDB, CREATEROLE, CREATEEXTTABLE, LOGIN, RESOURCE GROUP, and RESOURCE QUEUE. Properties must be set on each user-level role.
Due to backward compatibility, the INHERIT property is the default property. In previous YMatrix database versions, users always had access to all privileges for the group they belong to. However, NOINHERIT provides a closer match to the semantics specified in the SQL standard.
Be careful when using CREATEROLE privileges. There is no concept of inheritance for the privilege of CREATEROLE-role. This means that even if one character does not have specific privileges but is allowed to create another role, it can easily create another role, which has a privilege different from its own role (except for creating a role with superuser privilege). For example, if a role has CREATEROLE privilege but does not have CREATEDB privileges, it can create a new role using CREATEDB privileges. Therefore, a role with CREATEROLE privilege is considered as an almost superuser role.
Superusers never execute the CONNECTION LIMIT option.
Care must be taken when specifying an unencrypted password using this command. Passwords will be transferred to the server in plaintext and may also be recorded in the client's command history or server log. However, the client program createuser transmits the encrypted password. Additionally, psql contains the command \password, which can be used to change passwords safely later.
Create a role that can be logged in but does not provide a password:
CREATE ROLE jonathan LOGIN;
Create a role that belongs to the resource queue:
CREATE ROLE jonathan LOGIN RESOURCE QUEUE poweruser;
Create roles with passwords that are valid until the end of 2016 (CREATE USER is the same as CREATE ROLE, except that it implies LOGIN):
CREATE USER joelle WITH PASSWORD 'jw8s0F4' VALID UNTIL '2017-01-01';
Create a role that can create a database and manage other roles:
CREATE ROLE admin WITH CREATEDB CREATEROLE;
Create a role that does not allow login access on Sunday:
CREATE ROLE user3 DENY DAY 'Sunday';
Create a role that can create a readable and writable external table of type 'gpfdist':
CREATE ROLE jan WITH CREATEEXTTABLE(type='readable', protocol='gpfdist')
CREATEEXTTABLE(type='writable', protocol='gpfdist');
Create a role and assign a resource group:
CREATE ROLE bill RESOURCE GROUP rg_light;
The SQL standard defines the concepts of users and roles, but treats them as different concepts and leaves all commands that define users to the database implementation specification. In the YMatrix database, users and roles are unified into single type objects. Therefore, roles have more optional attributes than in the standard.
CREATE ROLE is in the SQL standard, but this standard only requires the following syntax:
CREATE ROLE name [WITH ADMIN rolename]
The YMatrix database extension is a choice that allows multiple initial administrators, as well as all other options for CREATE ROLE.
By providing the user with NOINHERIT attribute and assigning the role to the INHERIT attribute, the behavior specified by the SQL standard can be closest to the closest.