Search
ctrl/
Ask AI
Light
Dark
System

Roles

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

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.

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 ...

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:

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 ;

The command drop role removes an existing role.

Remove a role:

Copy
drop role alice;