Chapter 6. Database User and Permission Management

Database Users

Database users are conceptually completely separate from any operating system users. In practice it might be convenient to maintain a correspondence, but this is not required. Database user names are global across a database cluster installation (and not per individual database). To create a user, use the CREATE USER SQL command:
CREATE USER name
name follows the rules for SQL identifiers: either without special characters, or double-quoted if you need to include special characters. To remove an existing user, use the DROP USER command:
DROP USER name

For convenience, the shell scripts createuser and dropuser are wrappers around these SQL commands.

In order to bootstrap the database system, a freshly initialized system always contains one predefined user. This user will have the same name as the operating system user that initialized the area (and is presumably being used as the user that runs the server). Thus, often an initial user "postgres" exists. In order to create more users you have to first connect as this initial user.

The user name to use for a particular database connection is indicated by the client that is initiating the connection request in an application-specific fashion. For example, the psql program uses the -U command-line option to indicate the user to connect as. The set of database users a given client connection may connect as is determined by the client authentication setup, as explained in the chapter "Client Authentication".

User Attributes

A database user may have a number of attributes that define the user's privileges and that interact with the client authentication system.

superuser

A database superuser bypasses all permission checks. Only a superuser can create new users. To create a database superuser, enter:
CREATE USER name CREATEUSER

database creation

A user must be explicitly given permission to create databases (except for superusers, since those bypass all permission checks). To create such a user, enter:
CREATE USER name CREATEDB

password

A password is significant only if password authentication is used for client authentication. Database passwords are separate from any operating system passwords. To specify a password when creating a user, enter:
CREATE USER name WITH PASSWORD 'string'

Refer to the Red Hat Database SQL Guide and Reference and to the reference pages for CREATE USER and ALTER USER for details.