1

Good Day!

I got an error when I try to connect to db Google Cloud by dint of slonik:

const pool = createPool(
`socket:userName:password@/cloudsql/teest-123986:europe-west3:test?db=dbName`
)

I got:

error: throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string')

When I checked I saw that password = null (parser of string gave incorrect value).

I used this guide for connection string.

Why I got this error?

Andres
  • 51
  • 1
  • 6
  • https://github.com/gajus/slonik/discussions/290 says you need to use `socket://` not `socket:` in front of username+password – Bergi Feb 15 '22 at 16:03
  • Why connect via a unix socket instead of ssl? Does the database even run on the same host? – Bergi Feb 15 '22 at 16:03
  • "need to use socket:// not socket:" unfortunatly I tried "socket://" and I got error "wrong url". "Why connect via a unix socket instead of ssl?" I used old way which was using in the project (it is legacy code). It worked early. "Does the database even run on the same host?" I can connect to the database using pgAdmin and I can connect to the local database. But I can't set connection between app engine and google cloude. – Andres Feb 15 '22 at 17:11
  • "*It worked early.*" - how? Were you using a different db library? Please post the working setup – Bergi Feb 15 '22 at 17:30
  • That a local pgAdmin can connect via sockets to the local database, on the same machine, does not mean you can use sockets to connect from the app engine to a cloud database. Use a normal connection string with the full url of the database. – Bergi Feb 15 '22 at 17:32
  • "It worked early. - how?" I posted working setup (url "soket:...."). But it is not working when I deployed new version. Parsing of connecting string is wrong and I get error "client password must be a string" (password is null). If I change url I get error "incorrect url". – Andres Feb 16 '22 at 06:58
  • I've been trying to make this work for 2 days and so far I haven't found any reason why the url is accepted by slonik, but it's parsed incorrectly. – Andres Feb 16 '22 at 07:02
  • "Use a normal connection string with the full url of the database" I have tried the following options: 1)postgresql://user:pass@/cloudsql/${process.env.CONNECTION_NAME}/namedb 2)socket://socket:user:pass@/cloudsql/${process.env.CONNECTION_NAME}?db=namedb 3)socket://user:pass@/cloudsql/${process.env.CONNECTION_NAME}?db=namedb (sources: https://github.com/gajus/slonik/discussions/290, https://github.com/brianc/node-postgres/tree/master/packages/pg-connection-string, https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING) I don't know what else to try.. – Andres Feb 16 '22 at 07:15
  • What exactly changed when you "*deployed new version*", a new version of what? Your code? – Bergi Feb 16 '22 at 13:08
  • Ah, it appears that [connecting via unix domain socket](https://cloud.google.com/sql/docs/postgres/connect-app-engine-standard#public-ip-default_1) is indeed the default approach. By "normal connection string" I meant what Google refer to as [connecting to private IP via TCP](https://cloud.google.com/sql/docs/postgres/connect-app-engine-standard#private-ip_1). – Bergi Feb 16 '22 at 13:16

1 Answers1

1

After many tries this connection string worked:

socket://${process.env.SQL_USER}:${process.env.SQL_PASSWORD}@${process.env.IP_DB_PRIVATE}?db=${process.env.DB}
Andres
  • 51
  • 1
  • 6