Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

psql: FATAL: database "<user>" does not exist

I'm using the PostgreSql app for mac (http://postgresapp.com/). I've used it in the past on other machines but it's giving me some trouble when installing on my macbook. I've installed the application and I ran:

psql -h localhost 

It returns:

psql: FATAL:  database "<user>" does not exist 

It seems I can't even run the console to create the database that it's attempting to find. The same thing happens when I just run:

psql  

or if I launch psql from the application drop down menu:

Machine stats:

  • OSX 10.8.4

  • psql (PostgreSQL) 9.2.4

Any help is appreciated.

I've also attempted to install PostgreSql via homebrew and I'm getting the same issue. I've also read the applications documentation page that states:

When Postgres.app first starts up, it creates the $USER database, which is the default database for psql when none is specified. The default user is $USER, with no password.

So it would seem the application is not creating $USER however I've installed->uninstalled-reinstalled several times now so it must be something with my machine.

I found the answer but I'm not sure exactly how it works as the user who answered on this thread -> Getting Postgresql Running In Mac: Database "postgres" does not exist didn't follow up. I used the following command to get psql to open:

psql -d template1 

I'll leave this one unanswered until someone can provide an explanation for why this works.

like image 606
Ryan Rich Avatar asked Jul 13 '13 19:07

Ryan Rich


People also ask

How do you fix database does not exist?

The SolutionEither do su - postgres in your command line to switch to that user, or log in as the postgres user on your computer. Once you have the database set up, you can use the -d option to the psql command or append the database name after all the other psql options, e.g. psql -H myhost database .

Does not exist error fatal database?

This is because, postgres isn't having a role with this name. To get rid of this error, you need to create this role. Make sure the name of the new role is same as showing in the error message.

What is fatal database error?

The fatal database error occurs because the software can identify the partner and relationship, but with no interchange selected, can not determine how to process the data.

What is Pg_isready?

pg_isready is a utility for checking the connection status of a PostgreSQL database server. The exit status specifies the result of the connection check.


1 Answers

It appears that your package manager failed to create the database named $user for you. The reason that

psql -d template1 

works for you is that template1 is a database created by postgres itself, and is present on all installations. You are apparently able to log in to template1, so you must have some rights assigned to you by the database. Try this at a shell prompt:

createdb 

and then see if you can log in again with

psql -h localhost 

This will simply create a database for your login user, which I think is what you are looking for. If createdb fails, then you don't have enough rights to make your own database, and you will have to figure out how to fix the homebrew package.

like image 74
Kirk Roybal Avatar answered Sep 24 '22 06:09

Kirk Roybal