1

To create user I executed the following queries:

CREATE DATABASE yourdbname;
CREATE USER username WITH ENCRYPTED PASSWORD 'yourpass';
GRANT ALL PRIVILEGES ON DATABASE yourdbname TO username;

I check if user was created this way:

su postgres
bash-4.2$ psql -h localhost -p 5432
psql (12.2)
Type "help" for help.
postgres=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 username  |                                                            | {}

postgres=# 

And now, when I want to connect:

$psql -h localhost -p 5432 -U username
psql: error: could not connect to server: FATAL:  database "username" does not exist

Could anyone say how to fix it?

2 Answers 2

0

Try:

$ psql -h localhost -p 5432 -U username yourdbname
Sign up to request clarification or add additional context in comments.

Comments

0

By default the psql always consider your default database name same as your user name. So to overcome this, make sure you are using -d dbname while connecting to database.

e.g ./psql -h localhost -p 5432 -d yourdbname -U username

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.