作者
digoal
日期
2019-04-05
标签
PostgreSQL , wal_recycle , wal_init_zero , cow , copy on write
背景
WAL文件是PG的REDO文件,一个文件默认16MB,写满后写下一个文件。下一个文件可能是以前写过的,通过重命名以及初始化(内容置为0)的方式重复使用。
对于一些COW(copy on write)文件系统(例如ZFS,写时拷贝),实际上置0的方式复用,反而不如直接创建一个新文件。所以PG 12支持了用户选择是否使用老的WAL复用方法,或者使用新的复用方法(创建新文件)。
```
Add wal_recycle and wal_init_zero GUCs.
author Thomas Munro tmunro@postgresql.org
Tue, 2 Apr 2019 09:37:14 +0800 (14:37 +1300)
committer Thomas Munro tmunro@postgresql.org
Tue, 2 Apr 2019 09:37:14 +0800 (14:37 +1300)
commit 475861b2615dd63ae8431d811749a6f9a15bbfd6
tree df88475a55eaa2bf359000628325d7b798f90521 tree | snapshot
parent 4b82664156c230b59607704506f5b0a32ef490a2 commit | diff
Add wal_recycle and wal_init_zero GUCs.
On at least ZFS, it can be beneficial to create new WAL files every
time and not to bother zero-filling them. Since it's not clear which
other filesystems might benefit from one or both of those things,
add individual GUCs to control those two behaviors independently and
make only very general statements in the docs.
Author: Jerry Jelinek, with some adjustments by Thomas Munro
Reviewed-by: Alvaro Herrera, Andres Freund, Tomas Vondra, Robert Haas and others
Discussion: https://postgr.es/m/CACPQ5Fo00QR7LNAcd1ZjgoBi4y97%2BK760YABs0vQHH5dLdkkMA%40mail.gmail.com
```
+ <varlistentry id="guc-wal-init-zero" xreflabel="wal_init_zero">
+ <term><varname>wal_init_zero</varname> (<type>boolean</type>)
+ <indexterm>
+ <primary><varname>wal_init_zero</varname> configuration parameter</primary>
+ </indexterm>
+ </term>
+ <listitem>
+ <para>
+ If set to <literal>on</literal> (the default), this option causes new
+ WAL files to be filled with zeroes. On some filesystems, this ensures
+ that space is allocated before we need to write WAL records. However,
+ <firstterm>Copy-On-Write</firstterm> (COW) filesystems may not benefit
+ from this technique, so the option is given to skip the unnecessary
+ work. If set to <literal>off</literal>, only the final byte is written
+ when the file is created so that it has the expected size.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry id="guc-wal-recycle" xreflabel="wal_recycle">
+ <term><varname>wal_recycle</varname> (<type>boolean</type>)
+ <indexterm>
+ <primary><varname>wal_recycle</varname> configuration parameter</primary>
+ </indexterm>
+ </term>
+ <listitem>
+ <para>
+ If set to <literal>on</literal> (the default), this option causes WAL
+ files to be recycled by renaming them, avoiding the need to create new
+ ones. On COW filesystems, it may be faster to create new ones, so the
+ option is given to disable this behavior.
+ </para>
+ </listitem>
+ </varlistentry>
+
参考
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=475861b2615dd63ae8431d811749a6f9a15bbfd6
PostgreSQL 许愿链接
您的愿望将传达给PG kernel hacker、数据库厂商等, 帮助提高数据库产品质量和功能, 说不定下一个PG版本就有您提出的功能点. 针对非常好的提议,奖励限量版PG文化衫、纪念品、贴纸、PG热门书籍等,奖品丰富,快来许愿。开不开森.
9.9元购买3个月阿里云RDS PostgreSQL实例
PostgreSQL 解决方案集合
德哥 / digoal's github - 公益是一辈子的事.





