【云圖說】第132期 小云妹帶您快速玩轉RDS實例操作(2)——刪除與退訂
1597
2025-04-01
postgresql里有很多和主備同步有關的參數,其中比較重要的兩個是synchronous_commit 和?synchronous_standby_names。下面我們來分析下這兩個參數。
1. synchronous_commit
這個參數用來設置事務提交返回客戶端之前,一個事務是否需要等待 WAL 記錄被寫入磁盤。合法的值是{local,remote_write,remote_apply,on,off}
默認的并且安全的設置是on。
local
當事務提交時,寫入本地磁盤即可,不用關心備機的情況。
remote_write:
表示流復制主庫提交事務時,需等待備庫接收主庫發送的wal日志流并寫入備節點操作系統緩存中,之后向客戶端返回成功,這種情況下備庫出現異常關閉時不會有已傳送的wal日志丟失風險,但備機操作系統異常宕機就有已傳送的wal丟失風險
這個選項帶來的事務響應時間較短。
on:
1 為on且沒有開啟同步備庫的時候,會當wal日志真正刷新到磁盤永久存儲后才會返回客戶端事務已提交成功,
2 當為on且開啟了同步備庫的時候(設置了synchronous_standby_names),必須要等事務日志刷新到本地磁盤,并且還要等遠程備庫也提交到磁盤才能返回客戶端已經提交.
remote_apply:
表示流復制主庫提交事務時,需等待備庫接收主庫發送的wal流并寫入wal文件,同時備庫已經完成回放,之后才向客戶端返回成功,簡單的說remote_apply 表示本地wal已落盤,備庫wal已落盤并且已經完成回放,這個設置保證了擁有兩份持久化的wal,同時備庫也已經完成了回放。
這個選項帶來的事務響應時間最長。
off:
當數據庫事務提交時不需要等待本地 wal buffer 寫入 wal 日志,立刻向客戶端返回成功
2. synchronous_standby_names
這個參數用來指定同步備機的列表,存放的是需要設置為同步備機的備機名稱,以逗號隔開。
Specifies a comma-separated list of standby names that can support synchronous replication, as described in Section 25.2.7. At any one time there will be at most one active synchronous standby; transactions waiting for commit will be allowed to proceed after this standby server confirms receipt of their data. The synchronous standby will be the first standby named in this list that is both currently connected and streaming data in real-time (as shown by a state of streaming in the pg_stat_replication view). Other standby servers appearing later in this list represent potential synchronous standbys. If the current synchronous standby disconnects for whatever reason, it will be replaced immediately with the next-highest-priority standby. Specifying more than one standby name can allow very high availability. The name of a standby server for this purpose is the application_name setting of the standby, as set in the primary_conninfo of the standby's walreceiver. There is no mechanism to enforce uniqueness. In case of duplicates one of the matching standbys will be chosen to be the synchronous standby, though exactly which one is indeterminate. The special entry * matches any application_name, including the default application name of walreceiver. If no synchronous standby names are specified here, then synchronous replication is not enabled and transaction commits will not wait for replication. This is the default configuration. Even when synchronous replication is enabled, individual transactions can be configured not to wait for replication by setting the synchronous_commit parameter to local or off. This parameter can only be set in the postgresql.conf file or on the server command line.
綜上可以看出,第一個參數控制的是事務提交的時候到底要不要等備機以及怎么等,第二個參數控制的是那些節點可以成為同步備機。
PostgreSQL 云容災
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。