Parameter · Connections and Authentication / Connection Settings
unix_socket_directories
Sets the directories where Unix-domain sockets will be created.
- Default:
/var/run/postgresql - Type: string
- Applies: Restart required
In plain words
Programs on the same machine can connect through a special file (a Unix-domain socket) instead of the network. This setting says in which directory, or directories, PostgreSQL creates it.
Clients must look in the same place: psql -h /var/run/postgresql. A mismatch gives "No such file or directory".
For DBAs and operators
A comma-separated list; the server creates .s.PGSQL.<port> and a lock file .s.PGSQL.<port>.lock in each. An empty value disables Unix sockets. A value starting with @ creates a Linux abstract-namespace socket (no file, so file permissions do not apply). The compiled-in default is /tmp upstream; Debian/Ubuntu and RHEL packages use /var/run/postgresql (RHEL often both). This matters because libpq uses its own compiled-in default when no host is given.
Classic ticket: psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory — the server is running but put its socket elsewhere, or uses another port. Fix with -h /var/run/postgresql or PGHOST.
systemd's PrivateTmp=true hides a socket created in /tmp from other services. Directories under /run are cleared at boot, so packages recreate them with tmpfiles.d. Since the socket path is part of a local connection, pg_hba.conf local lines (often peer) apply to it.
How to change it
Change in postgresql.conf or ALTER SYSTEM, then restart the server.
See it in context
Postmaster Client authentication Server startup sequence Wire protocol
Related parameters
unix_socket_permissions unix_socket_group port listen_addresses