To create a user, use the CREATE USER command:

   CREATE USER username

Username follows the same syntactical rules as SQL identifiers. When specifying a username , it can either be with special characters inside quotes, or with plain letters a through z without quotes.

When removing a user from the database, use the DROP USER command. The shell scripts provide equivalent functionality with createuser and dropuser .

A newly installed system always contains a predefined user. This user is normally defined as the operating system user who performed the database initialization. Often, the postgres user is the initial user. You can log in as the postgres user to create and add other users into the database.

A user can connect as several different user names at one time. The psql program allows this through the use of the optional -u in the command line. It can be used like so:

    psql -u databasename  
When it asks for a username, specify the username you want to log in as.

The number of database users a person can connect as is defined by the client authentication setup. Therefore, a user is not constrained to logging in only as the operating system user.

Before creating any users, we need to decide the type of access an employee user would have, could they create tables in the database or not... etc. The next section describes attributes that can be added to a user.

Help us make a better book, leave feedback. (