1

When I attempted to start my local Postgres server this afternoon, I was greeted with the following error message:

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"?

I attempted to follow the instructions in the top rated answer on the following question: psql: could not connect to server: No such file or directory (Mac OS X); however, the file /usr/local/var/postgres/postmaster.pid does not appear to exist.

I'm running on OS X Mavericks.


I'm not entirely sure if this will help narrow it down, but the last thing I did last night was try an OS X system utility called Yasu (http://yasuapp.net/). I can only assume when it restarted the system, that's when something went wrong.

Community
  • 1
  • 1
Jamie
  • 1,367
  • 3
  • 15
  • 24

1 Answers1

0

Use a command like ( netstat -ln; ps -ef ) | egrep '(postgres)|(postmaster)|(5432)' to try to determine whether or not an instance of the postgres server is running.

If the postmaster is not running, remove the postmaster.pid file and restart the database. Do not remove the postmaster.pid file without making sure the database is not running, and note that removing the postmaster.pid file without starting the database is pointless.

It may be wise to open your postgresql.conf file and see if the listen_addresses, port, unix_socket_directory, unix_socket_group, and unix_socket_permissions settings might be a source of issues.

Since the error message referenced specifically mentions the socket file, look most closely at unix_socket_directory, unix_socket_group, and unix_socket_permissions.

If unix_socket_directory is pointing somewhere other than /tmp, then various workarounds exist.

Alternatively, and presuming that the server is running, one might try to locate the socket file without looking in the postgresql.conf file, though this might make it a bit harder to address permissions, port, etc. issues. A tool like locate, find, etc., may be used in conjunction with sudo or by the root user.

$ sudo find /tmp /var -name .s.PGSQL.5432

Presuming that the location of the .s.PGSQL.5432 file issue is the root cause of your problem, specifying the socket file location on the psql command-line is probably the most straightforward workaround. In example, if the *.s.PGSQL.5432 file is in /var/pgsql_socket directory as it is on some systems, try this, but, of course, use the actual directory where .s.PGSQL.5432 is located:

$ pgsql -h /var/pgsql_socket

If the .s.PGSQL.5432 file IS in /tmp, then the problem is more likely one of permissions, and consulting the postgresql.conf file is advised, and probably the user attempting the psql command will have to be added to a group that has access to the socket file. (Remember, log out and back in after changing group membership.)

kbulgrien
  • 3,989
  • 2
  • 22
  • 39
  • the OP stated: "the file /usr/local/var/postgres/postmaster.pid does not appear to exist" and this solution suggest deleting that file :-/ – mislavcimpersak Nov 30 '16 at 10:04
  • The answer avoids an assuming that because the "/usr/local/var/postgres/postmaster.pid does not appear to exist" that the most popular solution is invalid. The OP's wording indicates uncertainty. A postmaster.pid file might exist elsewhere due to a settings issue. This is taken into consideration. I don't think that the answer is invalidated on the point that the OP is not sure that the postmaster.pid file is an issue as the question did not provide evidence the the system configuration settings place the postmaster.pid file in the specified folder where the file was not found. – kbulgrien Nov 30 '16 at 14:45