How to create PostgreSQL User with superuser privileges

In this article, we will see how to create PostgreSQL User with superuser privileges by two ways.

Create PostgreSQL User/Role with superuser privileges by using either of following methods:
1. Create User/Role first then assign superuser privilege.
2. Create User/Role with superuser privileges.

1. Create User/Role then grant superuser privileges:

CREATE USER james with password 'James@123';

How to create PostgreSQL User with superuser privileges

Now, grant superuser privileges to the user:

ALTER USERjames with LOGIN SUPERUSER;

How to create PostgreSQL User with superuser privileges

2. Create PostgteSQL User/Role with superuser privileges:
We can create PostgreSQL User directly with superuser privilege with single statement.

CREATE USER david WITH LOGIN SUPERUSER PASSWORD 'david@123';

So in this article, we have seen how to create PostgreSQL User with superuser privileges by two ways.