Got host variable equals to the database hosts
host=<masters fqdn>,<replicas fqdn>
But, when the program tries to write something in db, it gets an error:
cannot set transaction read-write mode during recovery (SQLSTATE 0A000)
Looks like pgx tries to write into the replica , instead of master
I found out, this problem can be fixed by changing connection opts:
cfg.Config.RuntimeParams["target_session_attrs"] = "read-write"
But this doesn't work
Please help me solve this problem
Your server is in recovery mode and you're attempting to perform a write operation on a replica which is typically read-only during recovery.
You need to set
hot_standby = on
inpostgresql.conf
on replicas and confirmmax_wal_senders
andwal_level = replica
on the primary. In your primary server'spostgresql.conf
, thesynchronous_standby_names
parameter is probably set to an empty string, which should be changed to your standby name. And, remove anyrecovery.conf
orrecovery.signal
file there is - these files are used to control the recovery process and might contain settings that affect read-only vs. read-write behavior.Restart the server on both, the primary and the replica for the settings to take effect.