Manual Reference Pages - CREATE_ROLE (7)
CREATE_ROLE - define a new database role
CREATE ROLE name [ [ WITH ] option [ ... ] ]
where option can be:
SUPERUSER | NOSUPERUSER
| CREATEDB | NOCREATEDB
| CREATEROLE | NOCREATEROLE
| CREATEUSER | NOCREATEUSER
| INHERIT | NOINHERIT
| LOGIN | NOLOGIN
| REPLICATION | NOREPLICATION
| BYPASSRLS | NOBYPASSRLS
| CONNECTION LIMIT connlimit
| [ ENCRYPTED | UNENCRYPTED ] PASSWORD password
| VALID UNTIL timestamp
| IN ROLE role_name [, ...]
| IN GROUP role_name [, ...]
| ROLE role_name [, ...]
| ADMIN role_name [, ...]
| USER role_name [, ...]
| SYSID uid
adds a new role to a
database cluster. A role is an entity that can own database objects and have database privileges; a role can be considered a
group, or both depending on how it is used. Refer to
Chapter 20, Database Roles, in the documentation
Chapter 19, Client Authentication, in the documentation
for information about managing users and authentication. You must have
privilege or be a database superuser to use this command.
Note that roles are defined at the database cluster level, and so are valid in all databases in the cluster.
The name of the new role.
These clauses determine whether the new role is a
superuser, who can override all access restrictions within the database. Superuser status is dangerous and should be used only when really needed. You must yourself be a superuser to create a new superuser. If not specified,
is the default.
These clauses define a roles ability to create databases. If
is specified, the role being defined will be allowed to create new databases. Specifying
will deny a role the ability to create databases. If not specified,
is the default.
These clauses determine whether a role will be permitted to create new roles (that is, execute
CREATE ROLE). A role with
privilege can also alter and drop other roles. If not specified,
is the default.
These clauses are an obsolete, but still accepted, spelling of
NOSUPERUSER. Note that they are
as one might naively expect!
These clauses determine whether a role
the privileges of roles it is a member of. A role with the
attribute can automatically use whatever database privileges have been granted to all roles it is directly or indirectly a member of. Without
INHERIT, membership in another role only grants the ability to
to that other role; the privileges of the other role are only available after having done so. If not specified,
is the default.
These clauses determine whether a role is allowed to log in; that is, whether the role can be given as the initial session authorization name during client connection. A role having the
attribute can be thought of as a user. Roles without this attribute are useful for managing database privileges, but are not users in the usual sense of the word. If not specified,
is the default, except when
is invoked through its alternative spelling
CREATE USER (CREATE_USER(7)).
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
attribute is a very highly privileged role, and should only be used on roles actually used for replication. If not specified,
is the default.
These clauses determine whether a role bypasses every row-level security (RLS) policy.
is the default. Note that pg_dump will set
by default, to ensure all contents of a table are dumped out. If the user running pg_dump does not have appropriate permissions, an error will be returned. The superuser and owner of the table being dumped always bypass RLS.
CONNECTION LIMIT connlimit
If role can log in, this specifies how many concurrent connections the role can make. -1 (the default) means no limit.
Sets the roles password. (A password is only of use for roles having the
attribute, but you can nonetheless define one for roles without it.) If you do not plan to use password authentication you can omit this option. If no password is specified, the password will be set to null and password authentication will always fail for that user. A null password can optionally be written explicitly as
These key words control whether the password is stored encrypted in the system catalogs. (If neither is specified, the default behavior is determined by the configuration parameter
password_encryption.) If the presented password string is already in MD5-encrypted format, then it is stored encrypted as-is, regardless of whether
is specified (since the system cannot decrypt the specified encrypted password string). This allows reloading of encrypted passwords during dump/restore.
Note that older clients might lack support for the MD5 authentication mechanism that is needed to work with passwords that are stored encrypted.
VALID UNTIL timestamp
clause sets a date and time after which the roles password is no longer valid. If this clause is omitted the password will be valid for all time.
IN ROLE role_name
clause lists one or more existing roles to which the new role will be immediately added as a new member. (Note that there is no option to add the new role as an administrator; use a separate
command to do that.)
IN GROUP role_name
is an obsolete spelling of
clause lists one or more existing roles which are automatically added as members of the new role. (This in effect makes the new role a
clause is like
ROLE, but the named roles are added to the new role
WITH ADMIN OPTION, giving them the right to grant membership in this role to others.
clause is an obsolete spelling of the
clause is ignored, but is accepted for backwards compatibility.
ALTER ROLE (ALTER_ROLE(7))
to change the attributes of a role, and
DROP ROLE (DROP_ROLE(7))
to remove a role. All the attributes specified by
can be modified by later
The preferred way to add and remove members of roles that are being used as groups is to use
clause defines an expiration time for a password only, not for the role
per se. In particular, the expiration time is not enforced when logging in using a non-password-based authentication method.
attribute governs inheritance of grantable privileges (that is, access privileges for database objects and role memberships). It does not apply to the special role attributes set by
ALTER ROLE. For example, being a member of a role with
privilege does not immediately grant the ability to create databases, even if
is set; it would be necessary to become that role via
SET ROLE (SET_ROLE(7))
before creating a database.
attribute is the default for reasons of backwards compatibility: in prior releases of
PostgreSQL, users always had access to all privileges of groups they were members of. However,
provides a closer match to the semantics specified in the SQL standard.
Be careful with the
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 the role
privilege but not the
privilege, nonetheless it can create a new role with the
privilege. Therefore, regard roles that have the
privilege as almost-superuser-roles.
includes a program
that has the same functionality as
(in fact, it calls this command) but can be run from the command shell.
option is only enforced approximately; if two new sessions start at about the same time when just one connection
remains for the role, it is possible that both will fail. Also, the limit 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 cleartext, and it might also be logged in the clients command history or the server log. The command
createuser(1), however, transmits the password encrypted. Also,
contains a command
that can be used to safely change the password later.
Create a role that can log in, but dont give it a password:
CREATE ROLE jonathan LOGIN;
Create a role with a password:
CREATE USER davide WITH PASSWORD jw8s0F4;
is the same as
except that it implies
Create a role with a password that is valid until the end of 2004. After one second has ticked in 2005, the password is no longer valid.
CREATE ROLE miriam WITH LOGIN PASSWORD jw8s0F4 VALID UNTIL 2005-01-01;
Create a role that can create databases and manage roles:
CREATE ROLE admin WITH CREATEDB CREATEROLE;
statement is in the SQL standard, but the standard only requires the syntax
CREATE ROLE name [ WITH ADMIN role_name ]
Multiple initial administrators, and all the other options of
CREATE ROLE, are
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 each database implementation. In
we have chosen to unify users and roles into a single kind of entity. Roles therefore have many more optional attributes than they do in the standard.
The behavior specified by the SQL standard is most closely approximated by giving users the
attribute, while roles are given the
SET ROLE (SET_ROLE(7)), ALTER ROLE (ALTER_ROLE(7)), DROP ROLE (DROP_ROLE(7)), GRANT(7), REVOKE(7), createuser(1)
|PostgreSQL 9.5.2 ||CREATE ROLE (7) ||2016 |
Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.