yetanalytics / lrsql

A SQL-based Learning Record Store
https://www.sqllrs.com
Apache License 2.0
91 stars 17 forks source link

Enable socket unix for postgres #235

Closed florianrusso closed 1 year ago

florianrusso commented 2 years ago

Hi, we run SQLRS on cloud run, in order to be secure we need java packages to handle unix sockets. What do you think about this? I will be more than happy to open a new pull request but I’m not sure how to do that not being used to clojure. I added the dependencies

  com.kohlschutter.junixsocket/junixsocket-core  {:mvn/version “2.5.0”}
Downloading: com/kohlschutter/junixsocket/junixsocket-native-common/2.5.0/junixsocket-native-common-2.5.0.jar from central
Error building classpath. Could not find artifact com.kohlschutter.junixsocket:junixsocket-core:jar:2.5.0 in central (https://repo1.maven.org/maven2/)
make: *** [test-h2] Error 1

I didn’t manage to make tests work. due to unfound jar, so I tried

  com.kohlschutter.junixsocket/junixsocket-core  {:mvn/version “2.3.4"}
clojure -M:test -m lrsql.test-runner --database h2
Syntax error compiling at (lrsql/util/cert.clj:50:39).
Unable to find static field: md5WithRSAEncryption_oid in class sun.security.x509.AlgorithmId

seems to work during install, but I have an issue to launch the tests locally (with or without any change) and thought it would be a better idea to use docker instead.

to test I updated the docker compose to share the postgresql UNIX socket

# Runs SQL LRS with Postgres - Provided for demonstration purposes only!
# To run: docker compose up
# See the Docker Compose docs for more info: https://docs.docker.com/compose/
services:
  db:
    image: postgres
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
      - ./postgres/socket:/var/run/postgresql
    environment:
      POSTGRES_USER: lrsql_user
      POSTGRES_PASSWORD: lrsql_password
      POSTGRES_DB: lrsql_db
  lrs:
    # build: . # switch to this for active dev
    image: yetanalytics/lrsql:latest
    command:
      - /lrsql/bin/run_postgres.sh
    ports:
      - “8080:8080”
    depends_on:
      - db
    volumes:
      - ./postgres/socket:/var/run/postgresql
    environment:
      LRSQL_API_KEY_DEFAULT: my_key
      LRSQL_API_SECRET_DEFAULT: my_secret
      LRSQL_ADMIN_USER_DEFAULT: my_username
      LRSQL_ADMIN_PASS_DEFAULT: my_password
      # If Postgres is too slow to start, increase this
      LRSQL_POOL_INITIALIZATION_FAIL_TIMEOUT: 10000
      LRSQL_DB_JDBC_URL: jdbc:postgresql://localhost/postgres?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory$FactoryAr&socketFactoryArg=/var/run/postgresql&sslMode=disable

docker compose-up give me

lrsql-lrs-1  | 15:54:32.717 [main] ERROR com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Exception during pool initialization.
lrsql-lrs-1  | org.postgresql.util.PSQLException: The SocketFactory class provided org.newsclub.net.unix.AFUNIXSocketFactory could not be instantiated.
lrsql-lrs-1  |  at org.postgresql.core.SocketFactoryFactory.getSocketFactory(SocketFactoryFactory.java:43)
lrsql-lrs-1  |  at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:204)
lrsql-lrs-1  |  at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
lrsql-lrs-1  |  at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223)
lrsql-lrs-1  |  at org.postgresql.Driver.makeConnection(Driver.java:400)
lrsql-lrs-1  |  at org.postgresql.Driver.connect(Driver.java:259)
lrsql-lrs-1  |  at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:121)
lrsql-lrs-1  |  at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:359)
lrsql-lrs-1  |  at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201)
lrsql-lrs-1  |  at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:470)
lrsql-lrs-1  |  at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561)
lrsql-lrs-1  |  at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:100)
lrsql-lrs-1  |  at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81)
lrsql-lrs-1  |  at lrsql.system.database$make_conn_pool.invokeStatic(database.clj:86)
lrsql-lrs-1  |  at lrsql.system.database$make_conn_pool.invoke(database.clj:33)
lrsql-lrs-1  |  at lrsql.system.database.Connection.start(database.clj:98)
lrsql-lrs-1  |  at com.stuartsierra.component$fn__391$G__385__393.invoke(component.cljc:5)
lrsql-lrs-1  |  at com.stuartsierra.component$fn__391$G__384__396.invoke(component.cljc:5)
lrsql-lrs-1  |  at clojure.lang.AFn.applyToHelper(AFn.java:154)
lrsql-lrs-1  |  at clojure.lang.AFn.applyTo(AFn.java:144)
lrsql-lrs-1  |  at clojure.lang.Var.applyTo(Var.java:705)
lrsql-lrs-1  |  at clojure.core$apply.invokeStatic(core.clj:669)
lrsql-lrs-1  |  at clojure.core$apply.invoke(core.clj:662)
lrsql-lrs-1  |  at com.stuartsierra.component$try_action.invokeStatic(component.cljc:118)
lrsql-lrs-1  |  at com.stuartsierra.component$try_action.invoke(component.cljc:117)
lrsql-lrs-1  |  at com.stuartsierra.component$update_system$fn__450.invoke(component.cljc:140)
lrsql-lrs-1  |  at clojure.lang.ArraySeq.reduce(ArraySeq.java:116)
lrsql-lrs-1  |  at clojure.core$reduce.invokeStatic(core.clj:6829)
lrsql-lrs-1  |  at clojure.core$reduce.invoke(core.clj:6812)
lrsql-lrs-1  |  at com.stuartsierra.component$update_system.invokeStatic(component.cljc:136)
lrsql-lrs-1  |  at com.stuartsierra.component$update_system.doInvoke(component.cljc:130)
lrsql-lrs-1  |  at clojure.lang.RestFn.invoke(RestFn.java:445)
lrsql-lrs-1  |  at com.stuartsierra.component$start_system.invokeStatic(component.cljc:164)
lrsql-lrs-1  |  at com.stuartsierra.component$start_system.invoke(component.cljc:156)
lrsql-lrs-1  |  at com.stuartsierra.component$start_system.invokeStatic(component.cljc:162)
lrsql-lrs-1  |  at com.stuartsierra.component$start_system.invoke(component.cljc:156)
lrsql-lrs-1  |  at com.stuartsierra.component.SystemMap.start(component.cljc:179)
lrsql-lrs-1  |  at lrsql.postgres.main$_main.invokeStatic(main.clj:16)
lrsql-lrs-1  |  at lrsql.postgres.main$_main.doInvoke(main.clj:15)
lrsql-lrs-1  |  at clojure.lang.RestFn.invoke(RestFn.java:397)
lrsql-lrs-1  |  at clojure.lang.AFn.applyToHelper(AFn.java:152)
lrsql-lrs-1  |  at clojure.lang.RestFn.applyTo(RestFn.java:132)
lrsql-lrs-1  |  at lrsql.postgres.main.main(Unknown Source)
lrsql-lrs-1  | Caused by: java.lang.ClassNotFoundException: org.newsclub.net.unix.AFUNIXSocketFactory
...

lrsql-lrs-1  | Exception in thread "main" clojure.lang.ExceptionInfo: Error in component :connection in system com.stuartsierra.component.SystemMap calling #'com.stuartsierra.component/start {:reason :com.stuartsierra.component/component-function-threw-exception, :function #'com.stuartsierra.component/start, :system-key :connection, :component #lrsql.system.database.Connection{:backend #lrsql.postgres.record.PostgresBackend{}, :conn-pool nil, :config {:pool-validation-timeout 5000, :pool-auto-commit true, :pool-maximum-size 10, :pool-minimum-idle 10, :pool-initialization-fail-timeout 10000, :pool-connection-timeout 30000, :pool-leak-detection-threshold 0, :pool-max-lifetime 1800000, :pool-transaction-isolation nil, :pool-keepalive-time 0, :pool-isolate-internal-queries false, :pool-enable-jmx false, :database {:db-port 5432, :db-name "lrsql_pg", :db-host "0.0.0.0", :db-jdbc-url "jdbc:postgresql://localhost/postgres?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory&socketFactoryArg=/var/run/postgresql&sslMode=disable", :db-catalog nil, :db-schema nil, :db-user nil, :db-properties nil, :db-password nil, :db-type "postgres"}, :pool-name nil, :pool-idle-timeout 600000}}, :system #<SystemMap>}

...

Caused by: com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: The SocketFactory class provided org.newsclub.net.unix.AFUNIXSocketFactory could not be instantiated.

references :

milt commented 2 years ago

On the dependency, I do not believe that Clojure's deps.edn can currently support "POM-only" artifacts which this lib uses post 2.4.0

Maven Dependency: junixsocket-core is now a POM-only artifact (pom).

However, if I take the non-optional dep it refers to, that seems to download:

com.kohlschutter.junixsocket/junixsocket-native-common {:mvn/version "2.5.1"}

I'm guessing the other error you saw with the older dep was due to a missing module in the java runtime we compile, I'll look into that. If the dep + module don't add too much weight or other complications, we'll add them.

milt commented 2 years ago

@florianrusso I've confirmed that junixsocket doesn't require any modules outside of java.base, so that is likely OK. I've pushed a docker image with the dep included, yetanalytics/lrsql:junixsocket-test, please try that out and see that works any better.

I'd also suggest checking the JDBC URL you're using, it looks like it has a $ that needs to be escaped, and also double check the subclass you use there "FactoryAr" as I think that might have a typo.

florianrusso commented 2 years ago

@milt Thanks for your quick reply.

I did some tests locally and still struggle to use unix socket.

the docker compose I used for my test, with the corrected jdbc thanks to you

version: '3'

services:
  postgres:
    image: postgres:13
    ports:
      - '5432:5432'
    environment:
      POSTGRES_USER: test-postgres-db
      POSTGRES_DB: test-postgres-db
      POSTGRES_HOST_AUTH_METHOD: trust
    volumes:
      - db_socket:/var/run/postgresql
      - db_data:/var/lib/postgresql/data

  sqllrs:
    image: yetanalytics/lrsql:junixsocket-test
    command:
      - /lrsql/bin/run_postgres.sh
    volumes:
      - db_socket:/var/run/postgresql
    ports:
      - '8086:8080'
    environment:
      LRSQL_API_KEY_DEFAULT: lrsql_api_key
      LRSQL_API_SECRET_DEFAULT: lrsql_secret
      LRSQL_ADMIN_USER_DEFAULT: lrsql_admin_user
      LRSQL_ADMIN_PASS_DEFAULT: lrsql_admin_password
      LRSQL_DB_JDBC_URL: "jdbc:postgresql://localhost/test-postgres-db?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory%24FactoryArg&socketFactoryArg=/var/run/postgresql&sslMode=disable&user=test-postgres-db"

    depends_on:
      - 'postgres'

volumes:
  db_data:
  db_socket:

docker-compose up give me a connection failed attempt. I double checked my JDBC url but seems good to me

``` postgres_1 | 2022-07-13 08:43:38.970 UTC [1] LOG: database system is ready to accept connections sqllrs_1 | 08:43:47.263 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting... sqllrs_1 | 08:43:48.450 [main] ERROR com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Exception during pool initialization. sqllrs_1 | org.postgresql.util.PSQLException: The connection attempt failed. sqllrs_1 | at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:331) sqllrs_1 | at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) sqllrs_1 | at org.postgresql.jdbc.PgConnection.(PgConnection.java:223) sqllrs_1 | at org.postgresql.Driver.makeConnection(Driver.java:400) sqllrs_1 | at org.postgresql.Driver.connect(Driver.java:259) sqllrs_1 | at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:121) sqllrs_1 | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:359) sqllrs_1 | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201) sqllrs_1 | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:470) sqllrs_1 | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) sqllrs_1 | at com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:100) sqllrs_1 | at com.zaxxer.hikari.HikariDataSource.(HikariDataSource.java:81) sqllrs_1 | at lrsql.system.database$make_conn_pool.invokeStatic(database.clj:86) sqllrs_1 | at lrsql.system.database$make_conn_pool.invoke(database.clj:33) sqllrs_1 | at lrsql.system.database.Connection.start(database.clj:98) sqllrs_1 | at com.stuartsierra.component$fn__391$G__385__393.invoke(component.cljc:5) sqllrs_1 | at com.stuartsierra.component$fn__391$G__384__396.invoke(component.cljc:5) sqllrs_1 | at clojure.lang.AFn.applyToHelper(AFn.java:154) sqllrs_1 | at clojure.lang.AFn.applyTo(AFn.java:144) sqllrs_1 | at clojure.lang.Var.applyTo(Var.java:705) sqllrs_1 | at clojure.core$apply.invokeStatic(core.clj:669) sqllrs_1 | at clojure.core$apply.invoke(core.clj:662) sqllrs_1 | at com.stuartsierra.component$try_action.invokeStatic(component.cljc:118) sqllrs_1 | at com.stuartsierra.component$try_action.invoke(component.cljc:117) sqllrs_1 | at com.stuartsierra.component$update_system$fn__450.invoke(component.cljc:140) sqllrs_1 | at clojure.lang.ArraySeq.reduce(ArraySeq.java:116) sqllrs_1 | at clojure.core$reduce.invokeStatic(core.clj:6829) sqllrs_1 | at clojure.core$reduce.invoke(core.clj:6812) sqllrs_1 | at com.stuartsierra.component$update_system.invokeStatic(component.cljc:136) sqllrs_1 | at com.stuartsierra.component$update_system.doInvoke(component.cljc:130) sqllrs_1 | at clojure.lang.RestFn.invoke(RestFn.java:445) sqllrs_1 | at com.stuartsierra.component$start_system.invokeStatic(component.cljc:164) sqllrs_1 | at com.stuartsierra.component$start_system.invoke(component.cljc:156) sqllrs_1 | at com.stuartsierra.component$start_system.invokeStatic(component.cljc:162) sqllrs_1 | at com.stuartsierra.component$start_system.invoke(component.cljc:156) sqllrs_1 | at com.stuartsierra.component.SystemMap.start(component.cljc:179) sqllrs_1 | at lrsql.postgres.main$_main.invokeStatic(main.clj:16) sqllrs_1 | at lrsql.postgres.main$_main.doInvoke(main.clj:15) sqllrs_1 | at clojure.lang.RestFn.invoke(RestFn.java:397) sqllrs_1 | at clojure.lang.AFn.applyToHelper(AFn.java:152) sqllrs_1 | at clojure.lang.RestFn.applyTo(RestFn.java:132) sqllrs_1 | at lrsql.postgres.main.main(Unknown Source) sqllrs_1 | Caused by: java.net.SocketException: Connection refused; errno=111 sqllrs_1 | at org.newsclub.net.unix.NativeUnixSocket.connect(Native Method) sqllrs_1 | at org.newsclub.net.unix.AFSocketImpl.connect0(AFSocketImpl.java:372) sqllrs_1 | at org.newsclub.net.unix.AFSocket.connect0(AFSocket.java:265) sqllrs_1 | at org.newsclub.net.unix.AFSocket.connect(AFSocket.java:234) sqllrs_1 | at org.postgresql.core.PGStream.createSocket(PGStream.java:241) sqllrs_1 | at org.postgresql.core.PGStream.(PGStream.java:98) sqllrs_1 | at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:109) sqllrs_1 | at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:235) sqllrs_1 | ... 41 common frames omitted sqllrs_1 | Exception in thread "main" clojure.lang.ExceptionInfo: Error in component :connection in system com.stuartsierra.component.SystemMap calling #'com.stuartsierra.component/start {:reason :com.stuartsierra.component/component-function-threw-exception, :function #'com.stuartsierra.component/start, :system-key :connection, :component #lrsql.system.database.Connection{:backend #lrsql.postgres.record.PostgresBackend{}, :conn-pool nil, :config {:pool-validation-timeout 5000, :pool-auto-commit true, :pool-maximum-size 10, :pool-minimum-idle 10, :pool-initialization-fail-timeout 1, :pool-connection-timeout 30000, :pool-leak-detection-threshold 0, :pool-max-lifetime 1800000, :pool-transaction-isolation nil, :pool-keepalive-time 0, :pool-isolate-internal-queries false, :pool-enable-jmx false, :database {:db-port 5432, :db-name "lrsql_pg", :db-host "0.0.0.0", :db-jdbc-url "jdbc:postgresql://localhost/test-postgres-db?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory%24FactoryArg&socketFactoryArg=/var/run/postgresql&sslMode=disable&user=wrong-user", :db-catalog nil, :db-schema nil, :db-user nil, :db-properties nil, :db-password nil, :db-type "postgres"}, :pool-name nil, :pool-idle-timeout 600000}}, :system #} sqllrs_1 | at com.stuartsierra.component$try_action.invokeStatic(component.cljc:120) sqllrs_1 | at com.stuartsierra.component$try_action.invoke(component.cljc:117) sqllrs_1 | at com.stuartsierra.component$update_system$fn__450.invoke(component.cljc:140) sqllrs_1 | at clojure.lang.ArraySeq.reduce(ArraySeq.java:116) sqllrs_1 | at clojure.core$reduce.invokeStatic(core.clj:6829) sqllrs_1 | at clojure.core$reduce.invoke(core.clj:6812) sqllrs_1 | at com.stuartsierra.component$update_system.invokeStatic(component.cljc:136) sqllrs_1 | at com.stuartsierra.component$update_system.doInvoke(component.cljc:130) sqllrs_1 | at clojure.lang.RestFn.invoke(RestFn.java:445) sqllrs_1 | at com.stuartsierra.component$start_system.invokeStatic(component.cljc:164) sqllrs_1 | at com.stuartsierra.component$start_system.invoke(component.cljc:156) sqllrs_1 | at com.stuartsierra.component$start_system.invokeStatic(component.cljc:162) sqllrs_1 | at com.stuartsierra.component$start_system.invoke(component.cljc:156) sqllrs_1 | at com.stuartsierra.component.SystemMap.start(component.cljc:179) sqllrs_1 | at lrsql.postgres.main$_main.invokeStatic(main.clj:16) sqllrs_1 | at lrsql.postgres.main$_main.doInvoke(main.clj:15) sqllrs_1 | at clojure.lang.RestFn.invoke(RestFn.java:397) sqllrs_1 | at clojure.lang.AFn.applyToHelper(AFn.java:152) sqllrs_1 | at clojure.lang.RestFn.applyTo(RestFn.java:132) sqllrs_1 | at lrsql.postgres.main.main(Unknown Source) sqllrs_1 | Caused by: com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: The connection attempt failed. sqllrs_1 | at com.zaxxer.hikari.pool.HikariPool.throwPoolInitializationException(HikariPool.java:596) sqllrs_1 | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:582) sqllrs_1 | at com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:100) sqllrs_1 | at com.zaxxer.hikari.HikariDataSource.(HikariDataSource.java:81) sqllrs_1 | at lrsql.system.database$make_conn_pool.invokeStatic(database.clj:86) sqllrs_1 | at lrsql.system.database$make_conn_pool.invoke(database.clj:33) sqllrs_1 | at lrsql.system.database.Connection.start(database.clj:98) sqllrs_1 | at com.stuartsierra.component$fn__391$G__385__393.invoke(component.cljc:5) sqllrs_1 | at com.stuartsierra.component$fn__391$G__384__396.invoke(component.cljc:5) sqllrs_1 | at clojure.lang.AFn.applyToHelper(AFn.java:154) sqllrs_1 | at clojure.lang.AFn.applyTo(AFn.java:144) sqllrs_1 | at clojure.lang.Var.applyTo(Var.java:705) sqllrs_1 | at clojure.core$apply.invokeStatic(core.clj:669) sqllrs_1 | at clojure.core$apply.invoke(core.clj:662) sqllrs_1 | at com.stuartsierra.component$try_action.invokeStatic(component.cljc:118) sqllrs_1 | ... 19 more sqllrs_1 | Caused by: org.postgresql.util.PSQLException: The connection attempt failed. sqllrs_1 | at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:331) sqllrs_1 | at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) sqllrs_1 | at org.postgresql.jdbc.PgConnection.(PgConnection.java:223) sqllrs_1 | at org.postgresql.Driver.makeConnection(Driver.java:400) sqllrs_1 | at org.postgresql.Driver.connect(Driver.java:259) sqllrs_1 | at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:121) sqllrs_1 | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:359) sqllrs_1 | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201) sqllrs_1 | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:470) sqllrs_1 | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) sqllrs_1 | ... 32 more sqllrs_1 | Caused by: java.net.SocketException: Connection refused; errno=111 sqllrs_1 | at org.newsclub.net.unix.NativeUnixSocket.connect(Native Method) sqllrs_1 | at org.newsclub.net.unix.AFSocketImpl.connect0(AFSocketImpl.java:372) sqllrs_1 | at org.newsclub.net.unix.AFSocket.connect0(AFSocket.java:265) sqllrs_1 | at org.newsclub.net.unix.AFSocket.connect(AFSocket.java:234) sqllrs_1 | at org.postgresql.core.PGStream.createSocket(PGStream.java:241) sqllrs_1 | at org.postgresql.core.PGStream.(PGStream.java:98) sqllrs_1 | at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:109) sqllrs_1 | at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:235) sqllrs_1 | ... 41 more sqllrs-socket-unix_sqllrs_1 exited with code 1 ```

To find where is the issue I tried to use a wrong JDBC url ...%24FactoryArg&socketFactoryArg=/var/run/wrong.... Give me Caused by: java.lang.NoSuchMethodException: org.newsclub.net.unix.AFUNIXSocketFactory.<init>() instead of connection refused. Wrong username will gave me the same error.

I also tried with a different volume with no success, the socket is visible locally.

    volumes:
      - ./postgres/socket:/var/run/postgresql
florianrusso commented 2 years ago

Hi,

have you tried the docker-compose posted in my previous message ? Is it something I do not use properly ?

milt commented 1 year ago

@florianrusso sorry, this got lost in the shuffle. I'll try out that compose and see what I can find.

milt commented 1 year ago

Looks like you need to provide the full path to the socket for it to work like jdbc:postgresql://localhost/test-postgres-db?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory%24FactoryArg&socketFactoryArg=/var/run/postgresql/.s.PGSQL.5432&sslMode=disable&user=test-postgres-db. When I tried it with that locally it worked.

I'll go ahead and bring the branch up to date and put the PR up for review to add socket support to the main image.

milt commented 1 year ago

Additionally, it looks like there was a typo in your port for SQL LRS, here is a full working template:

version: '3'

services:
  postgres:
    image: postgres:13
    ports:
      - '5432:5432'
    environment:
      POSTGRES_USER: test-postgres-user
      POSTGRES_DB: test-postgres-db
      POSTGRES_HOST_AUTH_METHOD: trust
    volumes:
      - db_socket:/var/run/postgresql
      - db_data:/var/lib/postgresql/data

  sqllrs:
    image: yetanalytics/lrsql:junixsocket-test
    command:
      - /lrsql/bin/run_postgres.sh
    volumes:
      - db_socket:/var/run/postgresql
    ports:
      - '8080:8080'
    environment:
      LRSQL_API_KEY_DEFAULT: lrsql_api_key
      LRSQL_API_SECRET_DEFAULT: lrsql_secret
      LRSQL_ADMIN_USER_DEFAULT: lrsql_admin_user
      LRSQL_ADMIN_PASS_DEFAULT: lrsql_admin_password
      LRSQL_DB_JDBC_URL: "jdbc:postgresql://localhost/test-postgres-db?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory%24FactoryArg&socketFactoryArg=/var/run/postgresql/.s.PGSQL.5432&sslMode=disable&user=test-postgres-user"

    depends_on:
      - 'postgres'

volumes:
  db_data:
  db_socket:
milt commented 1 year ago

junixsocket landed in main a while ago, so the instructions above should work fine with the latest tag. Closing