3

While trying to connect to postgres running locally on my workstation, I get:

$ sudo -u postgres psql -c "create role ..."
could not change directory to "/home/esauer/workspace/cfme"
psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

My postgres-server install creates sockets in /var/run/postgresql.

How do I get the client to look in the proper location?

Itchydon
  • 2,572
  • 6
  • 19
  • 33
etsauer
  • 347
  • 2
  • 6
  • 12

1 Answers1

8

Check the --host option with psql --help.

Then you can make it permanent by setting it in your .psqlrc user file.

In your case try:

psql -h /var/run/postgresql -d your_database

Fabrizio Mazzoni
  • 1,831
  • 2
  • 24
  • 46
  • 1
    So, the default "host" value is "local socket", but that doesn't tell me why it's looking in /tmp/ instead of /var/run for that socket – etsauer Mar 25 '14 at 17:50
  • OH, got it... 'psql -h /var/run/postgres' points psql to the proper directory for local sockets. Thanks/ – etsauer Mar 25 '14 at 19:19
  • 1
    What is the syntax for defining the host in `.psqlrc`? (`\set HOST /var/run/postgresql` did not work.) – Datz Jul 10 '18 at 12:15