Postgres with Unix Domain sockets in PyCharm

It can be quite tricky to configure PyCharm to use Postgresql with a AF_UNIX connection. This page will guide you through the process (Jan 2026).

Firstly, you'll need a copy of junixsocket, which you can get from here:

Download junixsocket-<version>-bin.tar.gz and extract it. You will need junixsocket-common-2.10.1.jar and junixsocket-native-common-2.10.1.jar.

Open the PyCharm "Data Sources and Drivers". Right-click on PostgreSQL and select Duplicate.

Screenshot showing how to duplicate the Postgres driver

Give the new driver a name, such as "PostgreSQL (unix domain socket)".

In the General tab, click + under Driver Files to add the two jar files from junixsocket.

Remove the existing URL templates and use this:

Screenshot showing the new jar files general options

In the Advanced tab, set the following options:

socketFactory
org.newsclub.net.unix.AFUNIXSocketFactory$FactoryArg
socketFactoryArg
/var/run/postgresql/.s.PGSQL.5432
sslmode
disable

(You need to set socketFactoryArg even though you will override it with the templated connection URL.)

Use Tab to change the focus away from the setting you just changed, then click Apply to store the changes.

Screenshot showing the advanced settings

Now create a new data source using the driver you just configured.

Screenshow showing the how to make a data source using the new driver

Leave the host as localhost, or make it blank.

If your database username matches your unix username, you can leave the user blank.

If your server is configured to use peer authentication (it often will be), leave the password blank.


Valid HTML 4.01! Valid CSS!

Peter Benie <peterb@chiark.greenend.org.uk>
Linux