chirzul.maula
chirzul.maula

Reputation: 11

Unable to connect to multiple host in postgres : missing = after \"host1,\" in connection info string

I want to make connection in postgres with this dsn format: user=username password=password host=host1, host2, host3 port=5432 database=db_aob sslmode=prefer target_session_attrs=read-write

but i got error "missing "=" after "host1," in connection info string"

i try to remove space between host, but i got error "dial tcp: lookup host1,host2,host3: no such host"

is my dsn format wrong?

i connect with package database/sql in golang

Upvotes: 0

Views: 265

Answers (1)

Ry-
Ry-

Reputation: 225193

The PostgreSQL driver you’re using, lib/pq, doesn’t support multiple hosts. You’ll need to use a different driver, like jackc/pgx, which does:

ParseConfig supports specifying multiple hosts in similar manner to libpq. Host and port may include comma separated values that will be tried in order. This can be used as part of a high availability system.

Upvotes: 2

Related Questions