在连接字符串中使用多个主机时,Postgresql故障切换不起作用



我使用下面的python代码来测试故障转移,

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])

如果host1断开,则不会自动与host2建立连接。有人试过吗?

我想从我的应用程序连接到主实例,如果主实例坏了,那么我想回退到备用实例,它将是上面程序中的host2。

带有target_session_attrs="任何";它奏效了。它连接到列表中的下一个主机,该主机是备用

最新更新