Updated on 2026-10-21 GMT+08:00

Background Writer

This section describes background writer parameters. The background writer thread is used to write dirty page (new or modified data) in shared buffers to disks. It is designed to minimize or eliminate the waiting time caused by write operations (which are asynchronously performed by the background writer thread) when the database process executes user queries.

This mechanism also effectively reduces performance fluctuations caused by checkpoints. The background writer thread continuously refreshes dirty pages to disks. Therefore, when a checkpoint is triggered, only a small number of pages need to be refreshed. However, this mechanism increases the overall I/O load. In the traditional checkpoint interval, pages are refreshed only once though they may be repeatedly modified, while the background writer thread may refresh the pages multiple times in the same interval. Generally, continuous low load is better than periodic peak load. The parameters discussed in this section can be used to adjust the behavior based on actual requirements.

bgwriter_delay

Parameter description: Specifies the interval for periodically scanning dirty data in the buffer block by block. In full checkpoint mode, the amount of data written each time is controlled by the bgwriter_lru_maxpages parameter. After the data is written, the system sleeps for bgwriter_delay milliseconds and then repeats the operation. In incremental checkpoint mode, the system calculates the number of target idle buffer pages based on the specified candidate_buf_percent_target. If the number of candidate buffer pages is insufficient, the system scans 10 GB buffer pages every bgwriter_delay milliseconds. If dirty pages are found, the system flushes them to disks and adds them to the candidate linked list. If clean pages are found, the system directly adds them to the candidate linked list. In many systems, the effective resolution of the sleep delay is 10 milliseconds. Therefore, setting this parameter to a value that is not a multiple of 10 has the same effect as setting it to a value multiple of 10.

Parameter type: integer.

Unit: milliseconds

Value range: 10 to 10000

Default value: 2000 (2s)

Setting method: This is a SIGHUP parameter. Set it based on instructions provided in Table 1.

Setting suggestion:

  • Incremental checkpoint mode: If the data volume is multiple times the value of shared_buffers, the value of bgwriter_delay cannot be greater than 2s. If the data volume is smaller than the value of shared_buffers, the value of bgwriter_delay can be increased to save I/O resources.
  • Full checkpoint mode: Retain the default value. If the disk capability is poor, increase the value.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

candidate_buf_percent_target

Parameter description: Specifies the expected percentage of the candidate linked list of clean pages to the total number of pages in the buffer when incremental checkpointing is enabled. If the proportion of pages in the linked list of clean pages is less than the value of this parameter, the pagewriter thread starts, scans the buffer pages, adds clean pages to the linked list, flushes dirty pages to disks, and then adds dirty pages to the linked list.

Parameter type: floating-point number

Unit: none

Value range: 0.1 to 0.85

Default value: 0.3

Setting method: This is a SIGHUP parameter. Set it based on instructions provided in Table 1.

Setting suggestion: This parameter directly affects the number of pages flushed by the pagewriter thread. If the data volume is greater than the value of shared_buffers and candidate_buf_percent_target is set to an excessively small value, the performance is affected. If the data volume is twice or more of the value of shared_buffers, the value of this parameter cannot be smaller than the default value. In other scenarios, to reduce I/Os, set this parameter to a smaller value.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

bgwriter_lru_maxpages

Parameter description: Specifies the maximum number of dirty pages that can be flushed by the background writer thread each time.

Parameter type: integer.

Unit: none

Value range: 0 to 1000. 0 indicates that the background writer is disabled. This setting does not affect checkpoints.

Default value: 100

Setting method: This is a SIGHUP parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

bgwriter_lru_multiplier

Parameter description: The database kernel sets shared_buffers based on the current buffer size. If the value of shared_buffers is too small or too large when the kernel runs services, you can adjust the value of bgwriter_lru_multiplier to provide the optimal recommended value, the recommended value is the product of the value of this parameter and the value of shared_buffers. After you set this parameter to the recommended value, the setting takes effect when the database is restarted.

Parameter type: floating-point number

Unit: none

Value range: 0 to 10

Default value: 2

Setting method: This is a SIGHUP parameter. Set it based on instructions provided in Table 1.

Setting suggestion:

  • The number of dirty buffers written in each round depends on the number of buffers used by server processes during recent rounds. The estimated number of buffers used in the next round is calculated using the following formula: Average number of recently used buffers x bgwriter_lru_multiplier. The background writer writes dirty buffers until sufficient, clean, and reusable buffers are available. The number of buffers the background writer writes in each round is always equal to or less than the value of bgwriter_lru_maxpages.
  • Therefore, the value 1.0 of bgwriter_lru_multiplier indicates a just-in-time policy of writing exactly the number of dirty buffers predicted to be required. Larger values provide some cushion against spikes in demand, whereas smaller values intentionally leave more writes to be done by server processes.
  • Smaller values of bgwriter_lru_maxpages and bgwriter_lru_multiplier reduce the extra I/O load caused by the background writer, but make it more likely that server processes will have to issue writes for themselves, delaying response to queries.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

pagewriter_thread_num

Parameter description: Specifies the number of threads for backend page flushing after incremental checkpointing is enabled. Data is flushed to disks based on the sequence in which dirty pages are set to dirty, clean buffer pages are generated, and recovery points for checkpointing are pushed.

Parameter type: integer.

Unit: none

Value range: 1 to 16

Default value:

  • For the 8-core CPU/64 GB memory specification in hybrid deployment mode, the default value is 1.
  • For all specifications in independent deployment mode and other specifications in hybrid deployment mode, the default value is 4.

Setting method: This is a POSTMASTER parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

dirty_page_percent_max

Parameter description: Specifies the maximum expected percentage of dirty pages to shared_buffers after the incremental checkpoint is enabled. When the value of this parameter is reached, the background page flush thread flushes dirty pages based on the value of max_io_capacity.

Parameter type: floating-point number

Unit: none

Value range: 0.1 to 1

Default value: 0.9

Setting method: This is a SIGHUP parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

pagewriter_sleep

Parameter description: Specifies the dirty data flush period of the pagewriter page flush thread in incremental checkpoint mode.

Parameter type: integer.

Unit: milliseconds

Value range: 0 to 3600000

Default value: 2000 (2s)

Setting method: This is a SIGHUP parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value for CNs. Do not set this parameter to a value greater than 2s for DNs. If dirty pages are generated quickly, you are advised to set this parameter to a value ranging from 100 ms to 500 ms. If this parameter is set to a large value, redo points are updated slowly, affecting Xlog recycling.

Risks and impacts of improper settings: If the value is too large, the page flushing speed decreases and redo points are pushed too slowly, affecting Xlog reclamation. In addition, the instance needs to wait for the time specified by this parameter when being stopped. As a result, the process exit times out.

max_io_capacity

Parameter description: Specifies the maximum I/Os per second for the background writer to flush dirty pages in batches.

Parameter type: integer.

Unit: KB

Value range: 30720 to 10485760

Default value: 512000 (that is, 500 MB)

Setting method: This is a SIGHUP parameter. Set it based on instructions provided in Table 1. If the value of the parameter does not contain a unit, the default unit is KB. The unit can also be MB or GB. For example, if max_io_capacity is set to 512000, 512000kB, or 500MB, it indicates that max_io_capacity is 500 MB.

Setting suggestion: Set this parameter based on the service scenario and disk I/O capability of the host. For example, if the disk I/O bandwidth is 500 MB, you are advised to set the bandwidth to a value less than 500 MB. If a shorter RTO is required or a large capacity is required, you can increase the value of max_io_capacity, for example, 2 GB.

Risks and impacts of improper settings: If the value is too small, the dirty page flushing speed is slower than the dirty page generation speed. As a result, the dirty pages in the buffer are full and the performance deteriorates. If the value is too large, write amplification occurs, affecting the service life of the storage device.

enable_consider_usecount

Parameter description: Specifies whether the page eviction algorithm of the buffer considers the page popularity.

Parameter type: Boolean.

Unit: none

Value range:

  • on: The page popularity is considered.
  • off: The page popularity is not considered.

Default value: off

Setting method: This is a SIGHUP parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Enable this parameter in scenarios where single-page elimination is frequently performed, such as large-capacity scenarios.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

enable_buffer_evictor

Parameter description: Specifies whether to enable the intelligent eviction algorithm.

Parameter type: Boolean.

Unit: none

Value range:

  • on: The intelligent eviction algorithm is enabled.
  • off: The intelligent eviction algorithm is disabled.

Default value: off

Setting method: This is a SIGHUP parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Enable this parameter in scenarios where single-page elimination is frequently performed, such as large-capacity scenarios.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

eviction_clean_page_percent_min

Parameter description: Specifies the minimum number of clean pages reserved by the intelligent eviction algorithm. If the number of clean pages is less than the value of this parameter, the generation rate of candidate pages to be evicted is limited. If the value is set to 0, the generation rate is not limited.

Parameter type: floating-point number

Unit: none

Value range: 0 to 0.9

Default value: 0.1

Setting method: This is a SIGHUP parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Enable this parameter in scenarios where single-page elimination is frequently performed, such as large-capacity scenarios.

Risks and impacts of improper settings: If the value is too large, the dirty page flushing performance may deteriorate.

eviction_candidate_list_size

Parameter description: Specifies the length of the eviction queue of the intelligent eviction algorithm.

Parameter type: integer.

Unit: none

Value range: 1024 to 65536

Default value: 2048

Setting method: This is a POSTMASTER parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Enable this parameter in scenarios where single-page elimination is frequently performed, such as large-capacity scenarios.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

pagewriter_flush_mode

Parameter description: Specifies whether to enable the ultimate dirty page flushing function.

Parameter type: enumerated type

Unit: none

Value range:

  • extre_mode: The ultimate dirty page flushing function is enabled.
  • default_mode: The ultimate dirty page flushing function is disabled.

Default value: default_mode

Setting method: This is a POSTMASTER parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Enable this parameter in scenarios where single-page elimination is frequently performed, such as large-capacity scenarios.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

dw_file_num

Parameter description: Specifies the number of batch doublewrite files.

Parameter type: integer.

Unit: none

Value range: 1 to 16

Default value: 1

Setting method: This is a POSTMASTER parameter. Set it based on instructions provided in Table 1.

Setting suggestion: The value of this parameter is related to pagewriter_thread_num and cannot be greater than that of pagewriter_thread_num. If the value of dw_file_num is too large, the value is internally corrected to the value of pagewriter_thread_num.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

dw_file_size

Parameter description: Specifies the size of each doublewrite file.

Parameter type: integer.

Unit: MB

Value range: 32 to 256

Default value: 256

Setting method: This is a POSTMASTER parameter. Set it based on instructions provided in Table 1.

Setting suggestion: Retain the default value.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.

postmaster_parallel_init_thread_num

Parameter description: Specifies the number of parallel threads that can be used when the database is started.

Parameter type: integer.

Unit: none

Value range: 1 to 256

Default value: 16

Setting method: This is a POSTMASTER parameter. Set it based on instructions provided in Table 1.

Setting suggestion: This parameter indicates the number of threads for parallel initialization. Therefore, you are advised to set this parameter to a value less than or equal to the number of CPU cores minus 1.

Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.