'psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: database "myname" does not exist
I a rails app running on my local environment using postgresql. This morning I spun up a new one and after install the pg gem, etc. I am running into the following error when trying to run
psql
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: database "jackcollins" does not exist
What's strange is the db name "jackcollins" is from my other rails app.
I ran
pgrep -l postgres
and the output was
20902 postgres
20919 postgres
20920 postgres
20921 postgres
20922 postgres
20923 postgres
20924 postgres
I'm unsure how to proceed so that these apps can both run their own postgres instance.
Solution 1:[1]
Regarding the error, you are trying to connect to jackcollins, please can you test trying to connect using the database flag?:
psql -d your_database_name
Solution 2:[2]
I had the same problem as you, after making attempts to reinstall, rm -rf xxx.pid, etc., I ended up executing the following command and was eventually able to connect to the PostgreSQL database.
brew install postgresql- an error message appears
- run
createdb(because macs don't create username databases after installing PostgreSQL) - execute
psqlto connect successfully.
Solution 3:[3]
In the absence of -d <database_name> psql will use the OS user name as the database name. As in many things it better to be explicit rather then implicit, especially when working on a new instance. In addition use -h <host_name>, -p <port_number> and -U <user_name>. Then you know who you are connecting as, as well as how. It is spelled out here psql and since psql is a libpq program in more detail here Key words.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Anthony Sotolongo |
| Solution 2 | KE HUANG |
| Solution 3 |
