— Jun 17, 2013
One of the best ways to get PostgreSQL running quickly on your computer is Postgres.app. Unfortunately Postgres.app doesn’t enable connections via unix socket by default. I like to use sockets because they’re faster more secure.
The server is configured, by default, to allow connections by your username from
localhost on postgres’ default port
5432. If you don’t to specify the host
psql will attempt to connect via unix socket and fail with an error like:
$ psql psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
Note: The default socket location for the
psqlcommand is “/tmp”. The
psqlcommand I used during the writing of this article was configured to use “/var/pgsql_socket”.
The following steps will configure Postgres.app to allow connections via unix socket for a more flexible experience. Note: These instructions are tested against Mac OS X 10.8.
~/Library/Application Support/Postgres/var/postgresql.confin your favorite text editor.
#unix_socket_directory = ''and change it to
unix_socket_directory = '/var/pgsql_socket'.
/var/pgsql_socketif it doesn’t exist. (may require
chmod 770 /var/pgsql_socket. (may require
chown root:staff /var/pgsql_socket. (may require
Now you can connect to the server by unix socket!
$ psql psql (9.1.5, server 9.2.2) WARNING: psql version 9.1, server version 9.2. Some psql features might not work. Type "help" for help. your_username=#
Postgres.app 9.3 introduces app sandboxing
which changes the location for the configuration data to
This is a little confusing, especially considering the lack of documentation on the Postgres.app
site and in the docs. See this Github issue
for more information.
It’s also worth noting that from PostgreSQL 9.2 to 9.3 the unix socket configuration
so make sure your
postgresql.conf file uses the correct variable name!
Aaaaaaand they’ve taken sandboxing out in 9.3.1. To add to the fun, they’ve also
renamed the app to
Postgres93.app and adjusted the Application Support directory
accordingly. Now you can find the config file at:
Remember that you’ll probably want to update your
psql command is configured to use the “/tmp” directory, you may override this default
PGHOST environment variable. I include this line in my shell rc file: