postgresql 有动态数据源,主库挂了,java项目连接自动切换到从库,至少可以读数据吗? 等主库恢复了,又会自动切换到主库吗?
从库可以读取数据,在主库恢复期间,需要判断主库是否已经可以访问了,比喻程序中周期性的去尝试访问主库,当访问成功后,连接到主库
jdbc可以使用多ip,参考文章:https://www.modb.pro/db/22217
使用 JDBC 连接 PostgreSQL 数据库
targetServerType (String) 默认值 any允许仅打开与具有所需状态的服务器的连接,允许的值为any、primary、master、slave、secondary、preferSlave、preferSecondary和preferPrimary。
targetServerType (
)
any
primary
master
slave
secondary
preferSlave
preferSecondary
preferPrimary