Unix socket postgresql

Hi,

I have my PostgreSQL database running on a local unix socket:
config of my database:
unix_socket_directories = '/run/postgresql'

How do I connect jabref to this database? … as using /run/postgresql in the host/post field gives me the following error:

org.postgresql.util.PSQLException: Unable to parse URL jdbc:postgresql:///run/postgresql:5432/resources
	at org.jabref.merged.module@5.12.60000/org.postgresql.Driver.connect(Unknown Source)

Kind regards

Hm, I don’t know if we support this yet, from what I see Jabref tries to buidl the connection string as:
with host, port, database
jdbc:postgresql://%s:%d/%s

Therefore, you could try to percent-encode the host as the example from the docs

postgresql://%2Fvar%2Flib%2Fpostgresql/dbname 

Hmmm. I tried to fill into the host field:

%2Frun%2Fpostgresql

but it is not possible with the following error:

2024-05-17 23:19:34 [JavaFX Application Thread] org.jabref.logic.shared.DBMSConnection.<init>()
ERROR: Could not connect to database: The connection attempt failed. - Error code: 0

I guess I should make a request to fix this to accept /run/postgresql into the hostfield and not force a port,
or the possibility to add the whole jdbc string

Ah shit I see it’s the pattern we use which breaks it. I think an option for the whole jdbc string would also be a good idea.
“Expert configuration via JDBC string” as an additional option. This requires some more changes, but should be still doable. Will try to come up with something later or tomorrow

@bwakkie I came up with a solution which lets you specify the jdbc url (“enable expert mode” checkbox) and also now supports unix sockets through a factory:
You need to speficy the factory as parameter as well according to the docs
https://jdbc.postgresql.org/documentation/use/#unix-sockets
https://builds.jabref.org/pull/11303/merge

@bwakkie Have you had a chance to test the version?

Hi @Siedlerchr , sorry for the late reply! As I understood the function is merged in mainline now?

So with the latest version (JabRef 5.16–2024-07-25–771c4cd, Linux 6.6.41-1-manjaro amd64
Java 21.0.2, JavaFX 22.0.2+4) I tried to use the “use expert mode”.

Unfortunatly it didn´t work or I do not understand what I should do

I have tried filling in multiple ways in the custom JDBC Url:

?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory$FactoryArg&socketFactoryArg=/run/portgresql
?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory$FactoryArg&socketFactoryArg=%2Frun%2Fpostgresql
?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory$FactoryArg&socketFactoryArg=/%2Frun%2Fpostgresql%2F
jdbc:postgresql://localhost/resources?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory$FactoryArg&socketFactoryArg=%2Fvar%2Frun%2Fpostgresql%2Fresources
jdbc:postgresql:%2F%2Flocalhost%2F?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory$FactoryArg&socketFactoryArg=%2Fvar%2Frun%2Fpostgresql%2Fresources

… but every time I am getting the following errors:

org.postgresql.util.PSQLException: The SocketFactory class provided org.newsclub.net.unix.AFUNIXSocketFactory$FactoryArg could not be instantiated.
or
java.sql.SQLException: No suitable driver found for socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory$FactoryArg&socketFactoryArg=%2Frun%2Fpostgresql

Maybe I am missing something?

Also when I am selecting “user expert mode”, should the mandatory fields like localhost/port/database/user still need to be mandatory? I cannot leave them empty.

EDIT: I have to add that at one point I was able to connect with the jabref source that was attached to the merge request (but cannot find it anymore). I remember it was a weird combination between the mandatory fields and the custom JDBC Url.