1. Home
  2. Home
  3. Documentation
  4. Connect
  5. Unix sockets
Last reviewed Edit this page on GitHub

Unix sockets

Reviewed 2026-05-22 against source:socketFactory and socketFactoryArg properties:878-897, socket factory instantiation:32-40

By adding junixsocket you can obtain a socket factory that works with the driver. Code can be found here and instructions here .

Dependencies for junixsocket are :

<dependency>
  <groupId>com.kohlschutter.junixsocket</groupId>
  <artifactId>junixsocket-core</artifactId>
  <version>2.10.1</version>
  <type>pom</type>
</dependency>

Use localhost as the connection host, and add ?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory$FactoryArg&socketFactoryArg=[path-to-the-unix-socket] to the connection URL.

For example, if the server listens on /tmp/.s.PGSQL.5432, use:

jdbc:postgresql://localhost/postgres?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory$FactoryArg&socketFactoryArg=/tmp/.s.PGSQL.5432

PostgreSQL normally defaults unix_socket_directories to /tmp, though that can be changed at build time or in server configuration. Some packaged installations use /var/run/postgresql, so the socket path may instead be /var/run/postgresql/.s.PGSQL.5432.