After recently setting up Postgresql on my Raspberry Pi I created an account which is not a power user. Initially to set this up I entered


from the terminal and then executed

createuser pi -P --interactive

I responded N for superuser Y for create databases Y for create new roles and then.

Create database test;

When I try to go to psql now using simply


I get

pi@raspberrypi:~ $ psql psql: FATAL:  database "pi" does not exist

I can go to psql test and create databases there, but I was wondering what causes this behavior.

Does terminal automatically pass the Pi user credentials to postgresql or is it logging me in with my system's Pi Account?

  • Creating a user account does NOT create a database for them to use in the same process. createdb -O pi pi and then you should be fine.
    – tink
    Apr 2 '19 at 22:28

You are not showing the psql command you are attempting to use to connect to your Postgresql server. Though, I can possibly explain what is going on without that information.

If you do not specify a user in your psql command, it tries to use the username you are currently logged in as. If you do not specify a database, it will attempt to load a database of the same name as the user.

The error you are getting is database "pi" does not exist which indicates it could not load the database pi. In your posted question, you mention creating the username pi and the database test. You would want to specify to load the test database in your psql command:

psql --dbname=test

If you were not logged in as the pi user, you would want to pass the username in your psql command:

psql --username=pi --dbname=test

If none of that works, post your psql command in your question and we can get a better idea of what is going on.

  • Thank you. I believe this is the case. I have edited the post to more accurately show what commands I am executing. When I have a chance to experiment with these options, I'll add a follow up comment. Thanks for helping a noob out. Apr 4 '19 at 14:23

I solved this by: sudo su postgres





then from the pi account when you just use psql it will let you into the pi database

otherwise when you do psql you have to specify a database to connect to (if you just do psql it thinks you want to connect to database pi(your unix username)

and if you wanted to connect to that test database from the pi account:

psql --dbname=test

this way psql doesnt try to connect you to the pi database.

hope this helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.