Multiple Postgres DB hosts (pgx and POSTGRES_SEEDS related)

Hi! I’m looking for a way to set DB connection string to multiple (2) DB hosts
As I see typically POSTGRES_SEEDS accepts single host, but underlying pgx library can handle connection strings using “host1:port,host2,host3” format what would be a solution for my setup
Any ideas how it could be achieved?

1 Like

Also interested in the answer for this question. @tihomir - something you can answer?

Whats the use case where you might need cluster to connect to multiple db?

Hi! It is about connecting to a DB (postgres) that has multiple hosts e.g. master-slave topology. I’ve seen that there is PGX driver available already, and this driver is able to connect to master by default. But I haven’t seen any examples on how to do it in temporal. Maybe there are some examples?

Updated:

figured out how to connect to master slave postgres, just add this to your persistence.default.sql config:

connectAttributes:
     target_session_attrs: read-write

Here is an example of my config:

persistence:
  defaultStore: default
  visibilityStore: visibility
  numHistoryShards: 512
  datastores: 
    default:
      sql:
        pluginName: "postgres12_pgx"
        driverName: "postgres12_pgx"
        databaseName: "temporal_dev"
        connectAddr: "some-host-1:5432,some-host-2:5432"
        connectProtocol: "tcp"
        user: temporal_dev
        password: "masked"
        connectAttributes:
          target_session_attrs: read-write
        maxConnLifetime: 1h
        maxConns: 10
        maxIdleConns: 10
        tls:
          enableHostVerification: false
          enabled: false
1 Like