By default configuration of PostgreSQL user called postgres and it comes with full super-admin access to entire PostgreSQL instance running on your operating system or in the Container. The below commands are helpful to create a database, username, password and grant permission for the user to access the specific database.
As we discussed above the postgres user has super-admin permission so switch user to postgres,
$ sudo su - postgres
Enter into the postgres database
$ psql
Then, execute the following commands, create a new database,
psql=# CREATE DATABASE <DATABASE>;
Create a user account with encrypted password,
psql=# CREATE USER <USER> WITH ENCRYPTED PASSWORD '<PASSWORD>';
Set grant privilege for the user to access the database,
psql=# GRANT CONNECT ON DATABASE <DATABASE> TO <USER>;
If you would like to change the password run the command below,
psql=# ALTER USER <username> WITH ENCRYPTED PASSWORD '<PASSWORD>';
Comments (0)