sql

ag 2023-11-16T04:23:32.188949Z

So I have this local DB, and I'm using :ssl true :sslcert, etc. in my db-spec. And when I connect to it with jdbc/get-connection, it works fine. I can send queries, etc. But I can't seem to get it working with a connection pool. It would complain that: "password authentication failed for user". What I am doing wrong?

Cam Saul 2023-11-16T04:24:47.649539Z

c3p0 or hikari?

ag 2023-11-16T04:26:24.246989Z

Both not working, with similar messages. c3p0 churns for a bit (like almost a minute) and then spits out: 'The server requested SCRAM-based authentication, but no password was provided', hikari fails faster

Cam Saul 2023-11-16T04:38:19.786079Z

Try seeing if you can get a connection with java.sql.DriverManager . That will probably pinpoint your issue

Cam Saul 2023-11-16T04:40:18.986179Z

If you don't want to debug that way you could reify a DataSource and have its implementation of getConnection call whatever you're using that's working and return that. With c3p0 you can create a PooledDataSource from a normal unpooled one

Cam Saul 2023-11-16T04:40:57.398449Z

Been a while since I used Hikari but I think you can do the same thing there

Cam Saul 2023-11-16T04:46:44.184859Z

Take a look at how I did it here for example. This lib is like a million years old but maybe it can point you in the right direction https://github.com/metabase/connection-pool

seancorfield 2023-11-16T06:26:33.430089Z

@ag What exactly is HikariCP failing with? Did you change :user to :username per the docs?

ag 2023-11-16T17:29:22.170109Z

The problem might be specific to CockroachDB. It has default root user. The root account has no password and is required to present a cert on SQL. That works with single connections, but seems to be problematic for connection pooling.

seancorfield 2023-11-16T18:50:08.518219Z

You probably need to provide those options differently. When you pass a db-spec in to HikariCP, it will only use the properties it knows about I suspect, but there is a datasource properties option that lets you pass additional properties directly through to the underlying JDBC driver I think...?

seancorfield 2023-11-16T18:51:35.491869Z

Are you using next.jdbc.connection/->pool for this? Did you read this part of the docs: If you need to pass in connection URL parameters, it can be easier to use next.jdbc.connection/jdbc-url to construct URL, e.g.,

(->pool HikariDataSource {:jdbcUrl (jdbc-url {:dbtype .. :dbname .. :useSSL false}) :username .. :password ..})

seancorfield 2023-11-16T18:52:33.206369Z

In addition, read https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.3.894/doc/getting-started#connection-pooling carefully for what the db-spec can contain for HikariCP (and it talks about the datasource properties in that section too).

ag 2023-11-16T19:14:43.538219Z

Yes, I'm experimenting with the ->pool fn. I'll keep trying. Thank you. And I'll try jdbc-url as well. I'll post an update once I figure this out.

seancorfield 2023-11-16T19:20:54.573569Z

Part of the issue is the mismatch between what HikariCP accepts as properties and what JDBC drivers at large accept. At work, we specify :maxLifetime and :maximumPoolSize which are HikariCP-specific, for example.

ag 2023-11-16T19:23:53.442589Z

the brownfield codebase I'm digging through uses c3p0 (the person who wrote the code no longer available), I probably will try to make it work with that. I'm gonna need to find some compelling reasons to suggest a switch to HikariCP.

ag 2023-11-16T19:24:26.543489Z

maybe I won't have to. It should work with either.

seancorfield 2023-11-16T19:26:02.457709Z

One "gotcha" is c3p0 uses user (as does JDBC) but HikariCP uses username.

seancorfield 2023-11-16T19:26:27.013439Z

(we used to use c3p0 and switched to HikariCP)

ag 2023-11-16T19:28:05.873019Z

Yay... it finally worked. I needed jdbc-url:

(with-open [ds (connection/->pool
                  ComboPooledDataSource
                  {:jdbcUrl (connection/jdbc-url db-spec)})]

ag 2023-11-16T19:28:45.106709Z

Gosh, I just needed to read the docs, paying a bit more attention.

ag 2023-11-16T19:29:01.128639Z

Thank you @seancorfield

seancorfield 2023-11-16T19:52:23.239899Z

Glad the docs are good 🙂