Neha Phatak
Neha Phatak

Reputation: 1

Postgresql failover is not working when using multiple hosts in connection string

I am using below python code to test failover,

import psycopg2
 
conn = psycopg2.connect(database="ccs_testdb", host="host1,host2", user="postgre_user",                                     
                        password="secret", port="5432", target_session_attrs="read-write")                                  
cur = conn.cursor()
cur.execute("select pg_is_in_recovery(), inet_server_addr()")
row = cur.fetchone()
print("recovery =", row[0])
print("server =", row[1])

if host1 goes down then connection is not established with host2 automatically. Does anyone have tried it?

I want to connect to master instance from my application and if master goes down then want to fallback to standby instance which would be host2 in above prog.

Upvotes: 0

Views: 865

Answers (1)

Neha Phatak
Neha Phatak

Reputation: 1

with target_session_attrs="any" it worked. Its connecting to next host in list which is standby

Upvotes: 0

Related Questions