PostgreSQL how to create user via console - psql

  • Last update: Apr 3, 2024
  • Views: 27
  • Author: Admin
PostgreSQL how to create user via console - psql

Colleagues hello to all.

In today's article, we'll talk about how you can create users through the psql console in a PostgreSQL database. PostgreSQL allows you to create any number of users, and usernames must consist of letters and numbers (there must always be a letter first) .

 

Article content:

  1. Creating a user via the psql console.

 

1. Creating a user via the psql console.

1.1. Create a user without the ability to access the database.

sql> CREATE ROLE inzhener WITH PASSWORD 'Qwerty123';

postgresql_create_user_psql


 

1.2. Creating a user with the ability to log into the database.

sql> CREATE ROLE inzhener WITH LOGIN PASSWORD 'Qwerty123';

postgresql_create_user_psql


 

1.3. Create a user who has the right to create other users in the database.

sql> CREATE ROLE inzhener WITH LOGIN CREATEROLE PASSWORD 'Qwerty123';

postgresql_create_user_psql

Now this user can create other users in the database just like you.


 

1.4. Create a user who has the right to create databases.

sql> CREATE ROLE inzhener WITH LOGIN CREATEDB PASSWORD 'Qwerty123';

postgresql_create_user_psql


 

1.5. We create a super user. With  SUPERUSER privilege, the user will be able to do absolutely anything with the database.

sql> CREATE ROLE inzhener WITH LOGIN SUPERUSER PASSWORD 'Qwerty123';

postgresql_create_user_psql


 

1.6. We create a user who will have the ability to create backups and the ability to implement replication.

sql> CREATE ROLE inzhener WITH LOGIN REPLICATION PASSWORD 'Qwerty123';

postgresql_create_user_psql


 

Thank you all, I hope that my article helped you in some way.

SIMILAR ARTICLES