Postgresql_JDBC_failover_Load-balance_负载均衡_故障切换

作者:瀚高PG实验室 (Highgo PG Lab)- 狮子歌歌
故障切换:

Connection Fail-over

To support simple connection fail-over it is possible to define multiple endpoints (host and port pairs) in the connection url separated by commas. The driver will try to once connect to each of them in order until the connection succeeds. If none succeed, a normal connection exception is thrown. The syntax for the connection url is:

jdbc:postgresql://host1:port1,host2:port2/database

The simple connection fail-over is useful when running against a high availability postgres installation that has identical data on each node. For example streaming replication postgres or postgres-xc cluster. For example an application can create two connection pools. One data source is for writes, another for reads.

负载均衡:

The write pool limits connections only to master node: jdbc:postgresql://node1,node2,node3/accounting?targetServerType=master .

And read pool balances connections between slaves nodes, but allows connections also to master if no slaves are available: jdbc:postgresql://node1,node2,node3/accounting?targetServerType=preferSlave&loadBalanceHosts=true

targetServerType Allows opening connections to only servers with required state, the allowed values are any, master, slave and preferSlave.

The master/slave distinction is currently done by observing if the server allows writes.

The value preferSlave tries to connect to slaves if any are available, otherwise allows falls back to connecting also to master.

loadBalanceHosts = boolean In default mode (disabled) hosts are connected in the given order. If enabled hosts are chosen randomly from the set of suitable candidates.

refer:https://jdbc.postgresql.org/documentation/94/connect.html#connection-parameters

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值