How to Create User in PostgreSQL Using PgAdmin

⚡ Smart Summary

Creating a user in PostgreSQL can be done visually in pgAdmin or with the CREATE USER command in the SQL Shell. You can then grant privileges with GRANT, modify roles with ALTER USER, and remove accounts with DROP USER.

  • 🖱️ Create in pgAdmin: Right-click Login/Group Roles, enter a name, set a password and privileges, then save to create the user.
  • 💻 CREATE USER Command: In the SQL Shell, CREATE USER name WITH options sets login, superuser, and password in one command.
  • 🔑 Grant Access: GRANT ALL PRIVILEGES ON DATABASE db TO user gives an existing user access to a database.
  • 🔧 ALTER USER: ALTER USER adjusts a role’s permissions, adding or revoking privileges such as SUPERUSER.
  • 🗑️ DROP USER: DROP USER removes an account, but only after it no longer owns any database objects.
  • 🧾 Role vs User: CREATE USER defaults to LOGIN, while CREATE ROLE defaults to NOLOGIN; otherwise they are the same.

How to Create User in PostgreSQL Using PgAdmin

How to Create PostgreSQL User in PgAdmin

Following is a step by step process on how to create user in PostgreSQL PgAdmin:

Step 1) Right click on Login

In the first step, Right click on Login Group Role -> Create -> Click on Login Group Role…

Create PostgreSQL User in PgAdmin

Step 2) Create Login/Group Role

Now, Enter the name for the Login

Create PostgreSQL User in PgAdmin

Step 3) Click on Definition & Enter Details

  1. Enter Password
  2. An expiry date for the account

Create PostgreSQL User in PgAdmin

Step 4) The Privilege section

  1. Toggle Can Login button to YES
  2. Toggle Superuser to YES

Create PostgreSQL User in PgAdmin

Step 5) The SQL section

  1. You will see the SQL query to create a user as per the selections made in previous steps
  2. Click Save button

Create PostgreSQL User in PgAdmin

Step 6) Role is created

Now, Role is reflected in the object tree.

Create PostgreSQL User in PgAdmin

Step 7) Create a Database

Now, assign owner myguru to it as shown in below create user Postgres example.

Create PostgreSQL User in PgAdmin

Step 8) The command line

Now, you can see the owner is myguru.

Create PostgreSQL User in PgAdmin

PostgreSQL Create a User SQLShell (Command Line)

You can create a user by using the command-line command

CREATE USER

This Postgres create user with password method is more convenient for programmers and administrators as they have access to the console of PostgreSQL server. Moreover, they need for Postgres user creation and execute with a single command in place of logging in and using the interface of the PostgreSQL client.

Syntax:

CREATE USER name [ WITH ] option [ ... ]

where option can be:

      SUPERUSER | NOSUPERUSER
    | CREATEDB | NOCREATEDB
    | CREATEROLE | NOCREATEROLE
    | INHERIT | NOINHERIT
    | LOGIN | NOLOGIN
    | REPLICATION | NOREPLICATION
    | BYPASSRLS | NOBYPASSRLS
    | CONNECTION LIMIT connlimit
    | [ ENCRYPTED ] PASSWORD 'password' | PASSWORD NULL
    | VALID UNTIL 'timestamp'
    | IN ROLE role_name [, ...]
    | IN GROUP role_name [, ...]
    | ROLE role_name [, ...]
    | ADMIN role_name [, ...]
    | USER role_name [, ...]
    | SYSID uid

Example:

CREATE USER tom;

will create a user tom

CREATE USER tom WITH SUPERUSER;

Will create a user tom with superuser privileges. Let’s see the following example.

Step 1) We are creating a superuser valid till 3rd April 2025 11:50:38 IST. Enter the following command

CREATE USER mytest WITH
	LOGIN
	SUPERUSER
	CREATEDB
	CREATEROLE
	INHERIT
	NOREPLICATION
	CONNECTION LIMIT -1
	VALID UNTIL '2025-04-03T11:50:38+05:30'
	PASSWORD '123456';

Create a User SQLShell

Step 2) Enter command \du into the checklist of users

Create a User SQLShell

NOTE: CREATE USER is same as CREATE ROLE command. The difference between the two commands is when the Postgres CREATE user command is written it is by default in the LOGIN state whereas NOLOGIN is assumed when the CREATE ROLE option is used.

Add an existing user to a Database

You can grant a user privileges to access a database.

Example, we grant user “mytest” all privileges on user guru99

GRANT ALL PRIVILEGES ON DATABASE guru99 TO mytest;

Add an existing user to a Database

After execution of the PostgreSQL add user command, user will able to access the database with the given permissions.

The command GRANT is very powerful. You can give granular privileges like Select, Insert, Update to a user.

PostgreSQL Updating USER

Altering Existing User Permissions

Now that our new user “mytest” exists you can use ALTER USER to change the permissions granted to the librarian.

The format of ALTER USER Postgres includes the name of the user followed by some options to tell PostgreSQL which permissive alterations to make:

ALTER USER role_specification WITH OPTION1 OPTION2 OPTION3;

Revoking Permissions

You need to use this command when you make a mistake and wrongly assign permission which you may want to revoke. You can use ALTER USER command with no prefix before the permissive options.

For example, we can remove the SUPERUSER status from mytest like:

ALTER USER mytest WITH NOSUPERUSER;

Using \du, you will observe that the Superuser privilege is removed.

Revoking Permissions

Assigning Permission

You can use user SUPERUSER permission back “mytest” using the following command

ALTER USER mytest WITH SUPERUSER;

Using \du, you will observe that the Superuser privilege is added.

Assigning Permission

PostgreSQL Deleting User

You can use delete any user if you are sure that the specific user is no longer for your database. Note that deleting the users will never affect the actual database.

Syntax: DROP USER [user]

To delete any user, you have to make certain that the user is an owner of the database. Otherwise, you may receive an error message.

ERROR:  role "username" cannot be dropped because some objects depend on it

Example:

  1. Account “myguru” is an owner of database “demoDB.”
  2. Enter command DROP USER myguru
  3. Error is shown

PostgreSQL Deleting User

Once we change the database owner, the user can be deleted

PostgreSQL Deleting User

Cheat Sheet

Here are important commands

Commands Description
CREATE USER [user]
Command to Create a User
ALTER USER role_specification
Altering Existing User Permissions
ALTER USER [user]
Revoking Permissions
ALTER USER [user name] WITH SUPERUSER
Assigning Permission
DROP USER [user]
Command to Delete a User

FAQs

In the psql shell, run the \du command to list all roles and their attributes. You can also query the system catalog with SELECT rolname FROM pg_roles to get the same information programmatically.

Use ALTER USER, for example ALTER USER mytest WITH PASSWORD ‘newpassword’. The change takes effect immediately. Passwords are stored encrypted, and only superusers or the user themselves can change them.

In PostgreSQL, users and roles are the same object. CREATE USER creates a role that can log in by default, while CREATE ROLE creates one that cannot log in unless you add the LOGIN attribute.

AI can generate CREATE USER, GRANT, and ALTER USER statements from a plain description of the access you need, and explain each privilege. This helps you apply least-privilege security without memorizing syntax.

Yes. AI can suggest granular GRANT commands that give only the required privileges, warn against granting broad superuser access, and recommend using roles to group permissions for easier, safer management.

Summarize this post with: