I have been reading this tutorial. There is the below command to login as a user:
# login as user "user"
psql -U user
when I execute the above command, I get an error saying the following:
psql: FATAL: role "user" does not exist
The only help I saw online was here, the have said the following:
FATAL: role "myusername" does not exist
By default PostgreSQL connects to the PostgreSQL user with the same name as the current unix user. You have not created a PostgreSQL user by that name in your database.
Create a suitable user, or specify a different username to connect with. In the command line tools the -U flag does this.
But I still don't quite understand why I am getting this error.
You have first to login in a linux shell as the user postgres
and than create new postgres user with the command createuser
. The system user postgres
is created automatically by the Postgres installer.
Execute this code in the console (change your_username
with a username of your choice):
sudo -u postgres -i
createuser -l -d -P your_username
Better you create a database with the same name too (this makes the login later easier):
createdb your_username -O your_username
Then you should be able to connect in psql with
psql -h localhost -U your_username
Please check to see if the user exists.
\dg
If not, you need what is missing in the tutorial and you edit it if necessary.
CREATE USER user WITH PASSWORD '<here you password>';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With