postgresql几个与主备同步有关的参数解析

网友投稿 1389 2022-05-28

postgresql里有很多和主备同步有关的参数,其中比较重要的两个是synchronous_commit 和 synchronous_standby_names。下面我们来分析下这两个参数。

1. synchronous_commit

这个参数用来设置事务提交返回客户端之前,一个事务是否需要等待 WAL 记录被写入磁盘。合法的值是{local,remote_write,remote_apply,on,off}

默认的并且安全的设置是on。

local

当事务提交时,写入本地磁盘即可,不用关心备机的情况。

remote_write:

postgresql的几个与主备同步有关的参数解析

表示流复制主库提交事务时,需等待备库接收主库发送的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小时内删除侵权内容。

上一篇:关于GANDCRAB勒索病毒的安全预警
下一篇:12.22 Linux查看系统资源的使用情况(vmstat命令)
相关文章