sql

All things SQL and JDBC...
41ph4_Ph4un 2020-03-21T08:14:33.256Z

Hi! Has anyone experienced issues with usernames that have either "-" or "_" in them when using HikariCP with next.jdbc?

41ph4_Ph4un 2020-03-21T08:16:42.258100Z

I'm currently experiencing weird behavior as when I connect to my PostgreSQL database without connection pools everything works fine, but when I add HikariCP into the equation I start getting errors like FATAL: no pg_hba.conf entry for host "192.168.99.1", user "foo", database "test-dev", SSL on, given I'd have username like foo-bar (for the sake of argument).

41ph4_Ph4un 2020-03-21T08:17:06.258600Z

this behavior happens both for usernames that have "-" or "_" in them.

41ph4_Ph4un 2020-03-21T08:19:14.260100Z

The authentication started to working when I modified all the usernames to not have those, but I have multiple infras with other tech stacks that work fine with PG and delimited usernames and I do like to use postfixes to differentiate users by type.

41ph4_Ph4un 2020-03-21T08:50:55.261700Z

hmm.. it seems I get the same issue from com.impossibl.postgres.jdbc.PGDriver and org.postgresql.Driver

41ph4_Ph4un 2020-03-21T08:52:46.262800Z

If I've understood correctly does that mean that the username get's malformed either by next.jdbc (I took a look at the code though, and to me it looks just fine!) or then by HikariCP?

41ph4_Ph4un 2020-03-21T09:02:47.263800Z

aha! 🤦 ... it seems that I had db-specwith :user instead of :username. goddamnit.. yeah forget it guys 😄

41ph4_Ph4un 2020-03-21T09:04:05.265200Z

it somehow magically managed to connect without the pool when i had :user as the keyword for username

41ph4_Ph4un 2020-03-21T09:17:02.266700Z

hmm.. actually that's a bit confusing.. so the documentations state that :user is used to define the connection username, yet when using connection pool the db-spec needs to use :username ? Is this documented somewhere?

41ph4_Ph4un 2020-03-21T09:24:46.267300Z

oh lookie! it actually is! No problem there 😄 just needed to RTFM

dharrigan 2020-03-21T12:00:09.267800Z

Try to avoid - in username and database (and table etc..) names. Otherwise you'll be escaping them all, each time.

dharrigan 2020-03-21T12:00:37.268200Z

<https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS>

41ph4_Ph4un 2020-03-21T12:49:06.273900Z

Yeah I'd definitely avoid them in tablenames. Usually I use specific naming for local dev infra that has some differentiation like '-dev' and '-test' for databases and same goes with some usernames (as I rarely type any queries manually that concern these) Production is different of course.