PostgreSQL的高可用和讀寫分離和負載均衡

除了使用第三方的pgpool、pgbouner、haproxy等外,PostgreSQL原生接口的也提供了參數 target_session_attrs 來設置any或read-write來設置,在PostgreSQL 14版本開始又添加了 read-only、primary、standby、prefer-standby 等選項來進行更為方便的設置。

而PostgreSQL 16版本開始又有關於負載均衡的新功能參數 load_balance_hosts ,目前有 disable (default) 和 random 可供設置

以下在原生的Streaming replication的HA架構提供一些讀寫分離的設置參考:

demo 的 HA的架構:

Master : 192.168.56.11

Slave: 192.168.56.12

當然上面除了IP也可以用對應的DNS主機名來設置或個別在 etc/hosts下設置

Last updated