0

PostgreSQL – Create superusers

Tested On

PostgreSQL 10.5

Superuser

Depending on a given installation of PostgreSQL, the default superuser may not be readily available but it is called postgres.

Users are Roles, Roles are Users

PostgreSQL represents users as roles. There are roles that can log in called login roles. There are roles contain other roles.  There are roles that both can log in and contain other roles.

For this post, we’ll just briefly touch on creating login roles and superuser roles.

Users and Groups

In the past, PostgreSQL use the terms user and groups. However, in the recent versions, those are no longer in used. For backward compatibility, CREATE USER and CREATE GROUP still work in current version, but shun them and use CREATE ROLE instead.

Create Login Roles

To create login roles, follow the example below.

The VALID line is optional and specifies when the role should expire and lose its privileges; the default is infinity, which means the role never expires. The CREATEDB modifier grants database creation rights to the new role.

Create Superuser Roles

First and foremost, we can create another superuser roles if the current role (account or user) is also a superuser, e.g., the initial postgres role

For more information, please visit https://www.postgresql.org/docs/10/static/sql-createrole.html.

Karl San Gabriel

Karl San Gabriel

Java and Enterprise Technologies Expert