1. 程式人生 > 其它 >postgresql之同步流複製陷阱

postgresql之同步流複製陷阱

根據同步流複製模式,需要等待至少一個備庫接受wal並返回確認資訊後主庫才向客戶端返回成功,一方面保障資料完整性,另一方面如果備庫宕機,主庫的寫操作將出現等待狀態,實驗環境為一主一備

模擬備庫故障

[postgres@localhost pg_root]$ pg_ctl stop -m fast
waiting for server to shut down....2021-11-01 05:15:10.927 EDT [3890] LOG:  received fast shutdown request
2021-11-01 05:15:10.928 EDT [3890] LOG:  aborting any active transactions
2021-11-01 05:15:10.928 EDT [3895] FATAL: terminating walreceiver process due to administrator command 2021-11-01 05:15:10.929 EDT [3892] LOG: shutting down 2021-11-01 05:15:10.932 EDT [3890] LOG: database system is shut down done server stopped

在主庫上查詢,查詢不受影響

postgres=# select * from ceshizhujixieru;
 id
----
  2
(1 row)

在主庫上插入資料,一直除以等待狀態

通常一主一備不會採用同步複製,因為備庫宕機後會對生產產生影響,postgresql支援一主多備,