背景
1.危险系数最高
关闭fsync。本该持久化同步写的(例如checkpoint,wal write)变成了异步,可能丢数据,同时会导致数据库的数据不一致,极度危险。
任何时候都不建议关闭fsync。
2.危险系数高
关闭full_page_write。
full page write用来防止data block的partial write。原理:每次checkpoint后第一次被修改(或新增)的数据块,需要COPY完整的数据块内容到wal,当数据库CRASH后,从最后一次成功的checkpoint开始采用WAL进行恢复,因此可以修复partial write的data block。
例如pg_basebackup, start_backup等物理备份操作,会强制开启full page write,因为我们COPY datafile时,数据库可以处于读写状态,可能会拷贝到PARTIAL BLOCK,有full page 的话,在恢复时,可以将这些partial block恢复到一致的状态。
什么时候可以没有风险的关闭full page write?
1、如果块设备对齐,并支持原子写(原子写大于或等于一个DATA FILE数据页的大小),可以关闭full_page_write。
postgres=# show block_size;block_size------------8192(1 row)
3.危险系数次高
data_sync_retry (boolean)
When set to off, which is the default, PostgreSQL will raise a PANIC-level error on failure to flush modified data files to the filesystem. This causes the database server to crash. This parameter can only be set at server start.
On some operating systems, the status of data in the kernel’s page cache is unknown after a write-back failure. In some cases it might have been entirely forgotten, making it unsafe to retry; the second attempt may be reported as successful, when in fact the data has been lost. In these circumstances, the only way to avoid data loss is to recover from the WAL after any failure is reported, preferably after investigating the root cause of the failure and replacing any faulty hardware.
If set to on, PostgreSQL will instead report an error but continue to run so that the data flushing operation can be retried in a later checkpoint. Only set it to on after investigating the operating system’s treatment of buffered data in case of write-back failure.
默认值是安全的。
如果你要设置为ON,务必确保OS层的fsync是可以retry并且可靠的。
《PostgreSQL 12 preview - 可靠性提升 - data_sync_retry 消除os层write back failed status不可靠的问题》
https://github.com/digoal/blog/blob/master/201903/20190309_03.md
4.危险系数次高

5.危险系数低
synchronous_commit (enum)
(The maximum delay is three times wal_writer_delay.)
wal_writer_delay (integer)
wal_writer_flush_after (integer)
6 无危险
commit_delay (integer)
commit_siblings (integer)
如何选择总结
参考





