mouse_00
mouse_00

Reputation: 673

Does PL/Proxy send query to replica if master is not available?

I have sharded and replicated Postgre database. I use CLUSTER + RUN way of running functions. I define target (master/replica) using CLUSTER param and shard using RUN ON. How can I make PL/Proxy run or not to run function on master, if originally target was replica, but it failed?

Upvotes: 0

Views: 90

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 246013

In PL/Proxy, you define shards via a libpq connection string. Now if a shard is replicated, you can simply use a connection string like

host=slave.myorg.com,master.myorg.com port=5432,5432 dbname=...

This will try to connect to the first host, and if that fails, it will fall back to the second host. PostgreSQL v14 has the additional connection string parameter target_session_attrs=prefer-standby to preferable connect to the standby server, even if it is not the first in the list.

Upvotes: 1

Related Questions