天天看點

PostgreSQL 流行 HA 方案

digoal

2016-10-30

postgresql , ha , zookeeper , etcd , haproxy , pacemaker , corosync , 高可用 , governor , stolon

資料庫的ha是一個比較經典的話題,幾乎所有的生産環境都會考慮給資料庫部署ha。

postgresql 的ha方案也很多,在我的git裡有兩個自定義的ha腳本,有興趣的童鞋可以參考一下原理。

<a href="https://github.com/digoal/sky_postgresql_cluster">單個虛拟ip, 自動failover, 手動failback, 需fence裝置</a>

<a href="https://github.com/digoal/postgresql_ha_with_primary_standby_2vip">雙虛拟ip, 自動failover, 自動failback, 需fence裝置</a>

市面上也有很多成熟的pg ha方案,本文收集了一些,僅供參考。

1. 流複制,同步複制/自動降級,pacemaker , corosync

<a href="http://clusterlabs.org/wiki/pgsql_replicated_cluster">http://clusterlabs.org/wiki/pgsql_replicated_cluster</a>

2. postgresql failover managed by zookeeper

<a href="http://www.openscg.com/2013/04/postgresql-clustering/">http://www.openscg.com/2013/04/postgresql-clustering/</a>

<a href="https://github.com/jinty/zgres">https://github.com/jinty/zgres</a>

3. 仲裁使用etcd, stolon,仲裁很強壯

<a href="http://zhangwensheng.cn/blog/post/vincent/postgresql_ha_stolon_etcd">http://zhangwensheng.cn/blog/post/vincent/postgresql_ha_stolon_etcd</a>

<a href="https://github.com/sorintlab/stolon">https://github.com/sorintlab/stolon</a>

<a href="https://sgotti.me/post/stolon-introduction/">https://sgotti.me/post/stolon-introduction/</a>

4. 仲裁使用etcd, governor,仲裁很強壯

<a href="https://github.com/compose/governor">https://github.com/compose/governor</a>

5. 其他,還有比如基于drbd,或者基于共享存儲的就不在羅列了。

如果沒有fence裝置,或者fence裝置不可信的話,又或者需要大面積的部署pg節點,建議考慮etcd的方案,仲裁節點比較強壯,可以信任。

同時根據需求部署同步,或異步的流複制備節點,pg_rewind處理時間線分歧等。