Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with Docker Compose - FATAL: database "root" does not exist (PostgresSQL) [duplicate]

I'm using Postgres.app for Mac. 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 application's documentation 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
like image 277
Ryan Rich Avatar asked Nov 20 '25 16:11

Ryan Rich


2 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 70
Kirk Roybal Avatar answered Nov 22 '25 15:11

Kirk Roybal


From the terminal, just Run the command on your command prompt window. (Not inside psql).

createdb <user>

And then try to run postgres again.

like image 40
Dhananjay Avatar answered Nov 22 '25 14:11

Dhananjay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!