{"Entry":{"collection":"guc","key":"bgwriter_flush_after","name":"bgwriter_flush_after","aliases":[],"metadata":{"baseline":false,"boot_human":"Not specified","boot_val":null,"category":"Resource Usage / Background Writer","category_zh":"","changed_in":["18"],"changes":[{"documentation_changed":false,"fields":{},"from":"9.5","status":"added","to":"9.6"},{"documentation_changed":true,"fields":{},"from":"9.6","status":"changed","to":"10"},{"documentation_changed":true,"fields":{},"from":"11","status":"changed","to":"12"},{"documentation_changed":false,"fields":{"extra_desc":{"from":null,"to":"0 disables forced writeback."}},"from":"17","status":"changed","to":"18"}],"content_hash":"f15ae54b75bafe3a9827e5b543bd10fb91cc44a584f910659e053043f4a0795f","context":"","default_changed_in":[],"default_history":[{"from":"9.6","to":"19","value":"512 KiB (64 × 8kB)"}],"editorial":{"advice":{"olap":"Bulk writes can reach bgwriter_flush_after limits continuously. Measure total bytes written, checkpoints, and storage queueing, not just foreground query latency.","oltp":"Tune bgwriter_flush_after only with bgwriter and checkpoint metrics. The goal is fewer backend writes and smoother latency without excessive repeated writes; change one dimension at a time.","small":"A small host usually needs conservative write smoothing. Aggressive bgwriter_flush_after can consume I/O needed by foreground work, so retain the default unless backend writes are a measured problem."},"mechanism":["After the background writer has written more than bgwriter_flush_after bytes, PostgreSQL asks the operating system to begin writing those page-cache pages toward storage. Zero disables the request.","The request is writeback smoothing, not a durability fsync. It can reduce large kernel flush stalls, but can also hurt workloads that benefit from retaining dirty data in the OS cache, and it has no effect on unsupported platforms.","The measured Docker/Linux boot value represents Linux behavior; PostgreSQL documents a platform-dependent default of 512kB on Linux and zero elsewhere. Backend and checkpointer writeback have separate thresholds. Its SIGHUP context allows configuration reload without a server restart."],"pitfalls":["Changing bgwriter_flush_after without applying its documented unit and configuration context.","Optimizing an isolated benchmark while ignoring concurrent aggregate resource use.","Assuming a configured value guarantees operating-system or storage behavior.","Failing to retest startup, failover, and workload latency after the change."],"references":[{"title":"PostgreSQL 19 Beta 4: bgwriter_flush_after","url":"https://www.postgresql.org/docs/19/runtime-config-resource.html#GUC-BGWRITER-FLUSH-AFTER"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["backend_flush_after","checkpoint_flush_after","bgwriter_delay","bgwriter_lru_maxpages","shared_buffers"],"summary":"bgwriter_flush_after — Number of pages after which previously performed writes are flushed to disk. Observed in PG9.6–19 Beta 4; its last measured boot default is 512 KiB (64 × 8kB) in PG19 Beta 4, with sighup context. This is a beta-snapshot fact and can change before PostgreSQL 19 GA."},"enumvals":[],"first_version":"9.6","group":"Resource Usage","group_slug":"resource","imported_at":"2026-09-27T17:57:30.877068+08:00","intro_commit":{"authored_at":"2016-02-19T12:13:05-08:00","discussion":[],"hash":"428b1d6b29ca599c5700d4bc4f4ce4c5880369bf","subject":"Allow to trigger kernel writeback after a configurable number of writes.","url":"https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=428b1d6b29ca599c5700d4bc4f4ce4c5880369bf"},"key":"bgwriter_flush_after","last_version":"20","max_val":"","min_val":"","name":"bgwriter_flush_after","position":44,"present_in":["9.6","10","11","12","13","14","15","16","17","18","19","20"],"short_desc":"Whenever more than this amount of data has been written by the background writer, attempt to force the OS to issue these writes to the underlying storage.","short_desc_zh":"","source_rev":"english-manuals:106144061190236216ed27e20cf9f39e8c3c94fa3c155be307cff414d517b3c4","unit":"","vartype":"integer"}},"Definition":{"Collection":"guc","Key":"bgwriter_flush_after","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"bgwriter_flush_after","SourceRevision":"english-manuals:106144061190236216ed27e20cf9f39e8c3c94fa3c155be307cff414d517b3c4","Facts":{"boot_val":"64","category":"Resource Usage / Background Writer","context":"sighup","description":"Whenever more than this amount of data has been written by the background writer, attempt to force the OS to issue these writes to the underlying storage. Doing so will limit the amount of dirty data in the kernel's page cache, reducing the likelihood of stalls when an fsync is issued at the end of a checkpoint, or when the OS writes data back in larger batches in the background. Often that will result in greatly reduced transaction latency, but there also are some cases, especially with workloads that are bigger than shared_buffers, but smaller than the OS's page cache, where performance might degrade. This setting may have no effect on some platforms. If this value is specified without units, it is taken as blocks, that is BLCKSZ bytes, typically 8kB. The valid range is between 0, which disables forced writeback, and 2MB. The default is 512kB on Linux, 0 elsewhere. (If BLCKSZ is not 8kB, the default and maximum values scale proportionally to it.) This parameter can only be set in the postgresql.conf file or on the server command line.","doc":{"anchor":"GUC-BGWRITER-FLUSH-AFTER","file":"runtime-config-resource.html","lang":"en","sha256":"2e207c599f0884dfbe594558c478a2c7c132578981071e980e2015f31dfce28c","slug":"18"},"documented":true,"enumvals":null,"extra_desc":"0 disables forced writeback.","lang":"en","max_val":"256","metadata_version":"18","min_val":"0","name":"bgwriter_flush_after","short_desc":"Number of pages after which previously performed writes are flushed to disk.","source":"pg-settings-source-snapshot","unit":"8kB","vartype":"integer"},"ManualEvidence":{"doc":{"anchor":"GUC-BGWRITER-FLUSH-AFTER","file":"runtime-config-resource.html","lang":"en","sha256":"2e207c599f0884dfbe594558c478a2c7c132578981071e980e2015f31dfce28c","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"bgwriter_flush_after","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"bgwriter_flush_after","Summary":"","BodyHTML":"\u003cp\u003e每当后台写入器写出的数据超过此数量时，就尝试强制操作系统将这些写操作发往底层存储。这样可以限制内核页缓存中的脏数据量，降低在检查点结束时调用 \u003ccode\u003efsync\u003c/code\u003e，或操作系统在后台以较大批次写回数据时发生停顿的可能性。通常，这能大幅降低事务延迟，但在某些情况下性能可能下降，尤其是工作负载大于\u003ca href=\"/docs/18/runtime-config-resource.html#GUC-SHARED-BUFFERS\" rel=\"nofollow\"\u003eshared_buffers\u003c/a\u003e而小于操作系统页缓存时。此设置在某些平台上可能没有效果。如果未指定单位，则以块为单位，即 \u003ccode\u003eBLCKSZ\u003c/code\u003e 字节，通常为 8kB。有效范围为 \u003ccode\u003e0\u003c/code\u003e（禁用强制写回）至 \u003ccode\u003e2MB\u003c/code\u003e。Linux 上的默认值为 \u003ccode\u003e512kB\u003c/code\u003e，其他平台为 \u003ccode\u003e0\u003c/code\u003e。（如果 \u003ccode\u003eBLCKSZ\u003c/code\u003e 不是 8kB，默认值和最大值将按比例变化。）此参数只能在 \u003ccode\u003epostgresql.conf\u003c/code\u003e 文件中或服务器命令行上设置。\u003c/p\u003e","SourceRevision":"2026-09-11@29c86d9","ContentHash":"7a857309c4ffbda893636c5d43108d8ba1f4422281dce4a479f6b4e63f9d2251","Payload":{"carried_from":"","carry_reason":"","doc_html":"\u003cp\u003e每当后台写入器写出的数据超过此数量时，就尝试强制操作系统将这些写操作发往底层存储。这样可以限制内核页缓存中的脏数据量，降低在检查点结束时调用 \u003ccode class=\"function\"\u003efsync\u003c/code\u003e，或操作系统在后台以较大批次写回数据时发生停顿的可能性。通常，这能大幅降低事务延迟，但在某些情况下性能可能下降，尤其是工作负载大于\u003ca href=\"/docs/18/runtime-config-resource.html#GUC-SHARED-BUFFERS\"\u003eshared_buffers\u003c/a\u003e而小于操作系统页缓存时。此设置在某些平台上可能没有效果。如果未指定单位，则以块为单位，即 \u003ccode class=\"symbol\"\u003eBLCKSZ\u003c/code\u003e 字节，通常为 8kB。有效范围为 \u003ccode class=\"literal\"\u003e0\u003c/code\u003e（禁用强制写回）至 \u003ccode class=\"literal\"\u003e2MB\u003c/code\u003e。Linux 上的默认值为 \u003ccode class=\"literal\"\u003e512kB\u003c/code\u003e，其他平台为 \u003ccode class=\"literal\"\u003e0\u003c/code\u003e。（如果 \u003ccode class=\"symbol\"\u003eBLCKSZ\u003c/code\u003e 不是 8kB，默认值和最大值将按比例变化。）此参数只能在 \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e 文件中或服务器命令行上设置。\u003c/p\u003e","doc_same_as":""}},"RequestedLocale":"zh-Hans","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","9.6"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
