PostgreSQL: Create and List User

visibility 9 comment 0 access_time 23 days ago languageEnglish

PostgreSQL is one of the popular open source relational SQL databases. If you don't have a PostgreSQL databases, you can configure one on your Windows Subsystem for Linux easily: Install PostgreSQL on WSL. The steps to install it on UNIX-alike systems are similar.

Create user

The following code snippets shows you how to create a database user.

Create user without password:

CREATE USER kontext;

Drop user:

drop user kontext;

Create user with password:

CREATE USER kontext WITH PASSWORD 'kontext';

Create user with password and also expiry date:

CREATE USER kontext WITH PASSWORD 'kontext' VALID UNTIL '2021-12-01';

Create user with password and roles:


The above statement creates a user with two default roles: create database and create role.

Show or list users


Example output:

postgres=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of
 kontext   | Create role, Create DB                                    +| {}
           | Password valid until 2021-12-01 00:00:00+11                |
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
copyright This page is subject to Site terms.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

More from Kontext
visibility 10,746
thumb_up 0
access_time 2 years ago
visibility 131
thumb_up 0
access_time 8 months ago