TL;DR: It was a network issue. Read the updates at the bottom for what I found.
Typing psql
, I can connect:
$ psql
psql (9.3.2)
Type "help" for help.
ben=#
Typing psql -h localhost
, I can’t connection:
$ psql -h localhost
psql: FATAL: database "ben" does not exist
How is psql
by itself different from psql -h localhost
? I read in the documentation that “If you omit the host name, psql will connect via a Unix-domain socket to a server on the local host….”
My problem is that I’m trying to connect to a local db using another tool (RazorSQL) and can’t figure out what to enter to be able to connect to the database.
I’m on Mac OS X Mavericks.
Update: it looks like it was a network issue, probably related somehow to my VPN (sigh). Restarting my mac fixed it. Still, I wish I could diagnose what was going on so I don’t have to reboot my machine if this happens again.
Update 2: We have a production postgres database that I would connect to by first connecting to our VPN, ssh-ing (ssh -L
…) into the production box via the command line, then connecting to the database in RazorSQL. It turns out that the SSH tunnel was on port 5432 (the default port for postgres). This was cool when the production DB was the only DB I would connect to because you would just connect to localhost and the postgresql client was none the wiser. This was less cool when I added a local instance of postgres that ALSO used port 5432. Changing the port for SSH to 5433 fixed the issue (I also had to update my connection profile to connect to localhost:5433).