PostgreSQL Mountain Lion socket issue PostgreSQL Mountain Lion socket issue postgresql postgresql

PostgreSQL Mountain Lion socket issue


According to the error message, the psql command that appears first in the $PATH has /tmp as the hard-coded default unix socket directory.

Since the actual directory is in fact /var/pgsql_socket, you should tell it explicitly rather than relying on the default:

$ psql -h /var/pgsql_socket [other options]

The same applies to other client-side commands like createdb, dropdb, createuser...

If you don't want to specify -h each time, it can be put into the PGHOST environment variable.

Some people also solve this by using TCP connections to localhost rather than using the Unix socket directory.

The root cause of this issue would be that after installing PostgreSQL on Mac OS X, the system ends up having two different instances of the postgres client set (the libpq library, psql and other associated utilities), one that is bundled with MacOS and the other that comes with the PostgreSQL installer.

Therefore yet another method is to change your $PATH so that the psql installed with PostgreSQL gets choosen before the one installed with the system (presumably /usr/bin/psql).


I encountered this same issue when installing PostgreSQL 9.2 via Homebrew. psql that comes with this build looks to /tmp for a socket when called without any options.

I didn't feel like adding any new environment variables like PGHOST or creating aliases for psql. There's nothing wrong with doing any of these things, but I just didn't feel like adding to the clutter of my environment.

So, why not just set unix_socket_directory in postgresql.conf to /tmp? I did:

unix_socket_directory = '/tmp'      # (change requires restart)#unix_socket_group = ''             # (change requires restart)#unix_socket_permissions = 0777     # begin with 0 to use octal notation

After a reload, I can just run $ psql with no -h option, without having added an alias or environment variable.


I had the same problem, and after doing what you'd done I also had to change my path so that /usr/local/bin (where Homebrew puts everything) comes before /usr/bin. I don't know why this isn't the default anymore, but it's easy to change.

sudo vi /etc/paths

then edit the file to have the /usr/local/bin line at the top.

Or alternately if you just want this change to happen for your specific user account, edit your ~/.bash_profile file:

touch ~/.bash_profilevi ~/.bash_profile

and add this line: export PATH="/usr/local/bin:$PATH"

then run source ~/.bash_profile for the changes to take effect.