How to Create PostgreSQL users

April 2, 2024 / How-to Guide

In this guide, we have explained how to create PostgreSQL users. In every default PostgreSQL installation, the postgres superuser is included. Initially, you need to connect to PostgreSQL as the postgres user before you can create additional users, referred to as roles.

Follow these steps to create a PostgreSQL user:

  1. Log in to the server’s root user using the command line:
    su – postgres
  2. Now, you can execute commands as the PostgreSQL superuser. To create a user, type:
    createuser –interactive –pwprompt.
  3. At the “Enter name of role to add:” prompt, type the user’s name.
  4. At the “Enter password for new role:” prompt, type a password for the user.
  5. Retype the password at the “Enter it again:” prompt.
  6. At the “Shall the new role be a superuser?” prompt, type ‘y’ to grant superuser access or ‘n’ otherwise.
  7. At the “Shall the new role be allowed to create databases?” prompt, type ‘y’ to allow the user to create new databases or ‘n’ otherwise.
  8. At the “Shall the new role be allowed to create more new roles?” prompt, type ‘y’ to allow the user to create new users or ‘n’ otherwise. PostgreSQL will then create the user with the specified settings.

This way, you can create PostgreSQL users. For latest KBs, visit our knowledge base section.

Spread the love