4 Database roles are conceptually completely separate from operating
5 system users. In practice it might be convenient to maintain a
6 correspondence, but this is not required. Database roles are global
7 across a database cluster installation (and not per individual
8 database). To create a role use the CREATE ROLE SQL command:
11 name follows the rules for SQL identifiers: either unadorned without
12 special characters, or double-quoted. (In practice, you will usually
13 want to add additional options, such as LOGIN, to the command. More
14 details appear below.) To remove an existing role, use the analogous
18 For convenience, the programs createuser and dropuser are provided as
19 wrappers around these SQL commands that can be called from the shell
24 To determine the set of existing roles, examine the pg_roles system
26 SELECT rolname FROM pg_roles;
28 or to see just those capable of logging in:
29 SELECT rolname FROM pg_roles WHERE rolcanlogin;
31 The psql program's \du meta-command is also useful for listing the
34 In order to bootstrap the database system, a freshly initialized system
35 always contains one predefined login-capable role. This role is always
36 a “superuser”, and it will have the same name as the operating system
37 user that initialized the database cluster with initdb unless a
38 different name is specified. This role is often named postgres. In
39 order to create more roles you first have to connect as this initial
42 Every connection to the database server is made using the name of some
43 particular role, and this role determines the initial access privileges
44 for commands issued in that connection. The role name to use for a
45 particular database connection is indicated by the client that is
46 initiating the connection request in an application-specific fashion.
47 For example, the psql program uses the -U command line option to
48 indicate the role to connect as. Many applications assume the name of
49 the current operating system user by default (including createuser and
50 psql). Therefore it is often convenient to maintain a naming
51 correspondence between roles and operating system users.
53 The set of database roles a given client connection can connect as is
54 determined by the client authentication setup, as explained in
55 Chapter 20. (Thus, a client is not limited to connect as the role
56 matching its operating system user, just as a person's login name need
57 not match his or her real name.) Since the role identity determines the
58 set of privileges available to a connected client, it is important to
59 carefully configure privileges when setting up a multiuser environment.