Roles​

This section describes the administrative commands pertaining to roles.

Create role​

Create a role.

  1. create superuser role name [ extending base [, ...] ]
  2. "{" subcommand; [...] "}" ;
  3. where subcommand is one of
  4. set password := password

Description​

The command create role defines a new database role.

superuser

If specified, the created role will have the superuser status, and will be exempt from all permission checks. Currently, the superuser qualifier is mandatory, i.e. it is not possible to create non-superuser roles for now.

name

The name of the role to create.

extending base [, …]

If specified, declares the parent roles for this role. The role inherits all the privileges of the parents.

The following subcommands are allowed in the create role block:

set password := password

Set the password for the role.

Examples​

Create a new role:

  1. create role alice {
  2. set password := 'wonderland';
  3. };

Alter role​

Alter an existing role.

  1. alter role name "{" subcommand; [...] "}" ;
  2. where subcommand is one of
  3. rename to newname
  4. set password := password
  5. extending ...

Description​

The command alter role changes the settings of an existing role.

name

The name of the role to alter.

The following subcommands are allowed in the alter role block:

rename to newname

Change the name of the role to newname.

extending …

Alter the role parent list. The full syntax of this subcommand is:

  1. extending name [, ...]
  2. [ first | last | before parent | after parent ]

This subcommand makes the role a child of the specified list of parent roles. The role inherits all the privileges of the parents.

It is possible to specify the position in the parent list using the following optional keywords:

  • first – insert parent(s) at the beginning of the parent list,

  • last – insert parent(s) at the end of the parent list,

  • before <parent> – insert parent(s) before an existing parent,

  • after <parent> – insert parent(s) after an existing parent.

Examples​

Alter a role:

  1. alter role alice {
  2. set password := 'new password';
  3. };

Drop role​

Remove a role.

  1. drop role name ;

Description​

The command drop role removes an existing role.

Examples​

Remove a role:

  1. drop role alice;