This section describes the administrative commands pertaining to roles.

Create a role.

CREATE SUPERUSER ROLE name [ EXTENDING base [, ...] ]
"{" subcommand; [...] "}" ;

where subcommand is one of

  SET password := password

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.

Create a new role:

Copy
CREATE ROLE alice {
    SET password := 'wonderland';
};

Alter an existing role.

ALTER ROLE name "{" subcommand; [...] "}" ;

where subcommand is one of

  RENAME TO newname
  SET password := password
  EXTENDING ...

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:

EXTENDING name [, ...]
   [ 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.

Alter a role:

Copy
ALTER ROLE alice {
    SET password := 'new password';
};

Remove a role.

DROP ROLE name ;

DROP ROLE removes an existing role.

Remove a role:

Copy
DROP ROLE alice;
Light
Dark
System