postgresql


User management All Versions

8.0
8.1
8.2
8.3
8.4
9.0
9.1
9.2
9.3
9.4
9.5

This draft deletes the entire topic.

inline side-by-side expand all collapse all

Examples

  • 1

    This will create a PostgreSQL user with niceusername username and very-strong-password password.

    CREATE USER niceusername with PASSWORD 'very-strong-password';
    

    Although this method is simple, it lets the clear password in the client history file. If using psql, it is advised to use the \password command to do that. If the user issuing the command is a superuser, the current password will not be asked.

    CREATE USER niceusername with LOGIN;
    \password niceusername
    
  • 1

    To support a given application, you often create a new user and database to match.

    The shell commands to run would be these:

    $ createuser -P blogger
    Enter password for the new role: ⚫⚫⚫⚫⚫⚫⚫⚫
    Enter it again: ⚫⚫⚫⚫⚫⚫⚫⚫
    
    $ createdb -O blogger blogger
    

    This assumes that pg_hba.conf has been properly configured, which probably looks like this:

    # TYPE  DATABASE        USER            ADDRESS                 METHOD
    host    sameuser        all             localhost               md5
    local   sameuser        all                                     md5
    

I am downvoting this example because it is...

Syntax

  • CREATE USER niceusername with PASSWORD 'very-strong-password';

Parameters

Parameters

Remarks

Remarks

Still have question about User management? Ask Question

Create a user with a password

1

This will create a PostgreSQL user with niceusername username and very-strong-password password.

CREATE USER niceusername with PASSWORD 'very-strong-password';

Although this method is simple, it lets the clear password in the client history file. If using psql, it is advised to use the \password command to do that. If the user issuing the command is a superuser, the current password will not be asked.

CREATE USER niceusername with LOGIN;
\password niceusername

Create user and matching database

1

To support a given application, you often create a new user and database to match.

The shell commands to run would be these:

$ createuser -P blogger
Enter password for the new role: ⚫⚫⚫⚫⚫⚫⚫⚫
Enter it again: ⚫⚫⚫⚫⚫⚫⚫⚫

$ createdb -O blogger blogger

This assumes that pg_hba.conf has been properly configured, which probably looks like this:

# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    sameuser        all             localhost               md5
local   sameuser        all                                     md5

Topic Outline