Cost-based Vacuum Delay
This feature allows administrators to reduce the I/O impact of the VACUUM and ANALYZE statements on concurrent database activities. It is often more important to prevent maintenance statements, such as VACUUM and ANALYZE, from affecting other database operations than to run them quickly. Cost-based vacuum delay provides a way for administrators to achieve this purpose.

Certain VACUUM operations hold critical locks and should be complete as quickly as possible. In GaussDB, cost-based vacuum delays do not take effect during such operations. To avoid uselessly long delays in such cases, the actual delay is the larger of the two calculated values:
- vacuum_cost_delay x accumulated_balance/vacuum_cost_limit
- vacuum_cost_delay x 4
Context
During the execution of the ANALYZE | ANALYSE (see "SQL Reference > SQL Syntax > A > ANALYZE | ANALYSE" in Developer Guide) and VACUUM (see "SQL Reference > SQL Syntax > V > VACUUM" in Developer Guide) statements, the system maintains an internal counter that keeps tracking the estimated cost of various I/O operations that are performed. When the accumulated cost reaches a limit (specified by vacuum_cost_limit), the thread performing the operation will sleep for a short period of time (specified by vacuum_cost_delay). Then, the counter resets and the operation continues.
By default, this feature is disabled. To enable this feature, set vacuum_cost_delay to a non-zero value.
vacuum_cost_delay
Parameter description: VACUUM starts the backend service thread to sort dead tuples in the data table, which conflicts with the service thread. If vacuum_cost_delay is set to the value of vacuum_cost_limit to control the impact of VACUUM on services, the VACUUM thread hibernates the time specified by vacuum_cost_delay and allocates resources to service threads for execution to ensure that services are not blocked by backend VACUUM. This parameter can be set at the PDB level.
Parameter type: Integer
Unit: millisecond
Value range: 0 to 100. The value 0 indicates that the cost-based vacuum delay feature is disabled, and a positive value indicates that the cost-based vacuum delay feature is enabled. In many systems, the effective resolution of the hibernation time is 10 milliseconds. Therefore, setting vacuum_cost_delay to a value that is not an integer multiple of 10 has the same effect as setting it to the next higher multiple of 10.
Default value: 0. In the PDB scenario, if this parameter is not set, the global settings will apply.
Setting method: This is a USERSET parameter. Set it based on instructions provided in Table 1.
Setting suggestion: This parameter is usually set to a small value, such as 10ms or 20ms. Adjusting vacuum's resource consumption is best done by changing other vacuum cost parameters.
Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.
vacuum_cost_page_hit
Parameter description: Specifies the estimated cost for VACUUM to clean up data pages hit in a buffer. This parameter can be set at the PDB level.
Parameter type: Integer
Unit: None
Value range: 0 to 10000
Default value: 1. In the PDB scenario, if this parameter is not set, the global settings will apply.
Setting method: This is a USERSET 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.
vacuum_cost_page_miss
Parameter description: Specifies the estimated cost for VACUUM to clean up data pages that do not hit in a buffer. This parameter can be set at the PDB level.
Parameter type: Integer
Unit: None
Value range: 0 to 10000
Default value: 10. In the PDB scenario, if this parameter is not set, the global settings will apply.
Setting method: This is a USERSET 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.
vacuum_cost_page_dirty
Parameter description: Specifies the cost of VACUUM cleanup dirty pages. If the data page to be cleaned up is a clean page, VACUUM cleanup generates an extra cost of flushing dirty pages to disks. You can set this parameter to specify the cost of VACUUM cleanup dirty pages. This parameter can be set at the PDB level.
Parameter type: Integer
Unit: None
Value range: 0 to 10000
Default value: 20. In the PDB scenario, if this parameter is not set, the global settings will apply.
Setting method: This is a USERSET 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.
vacuum_cost_limit
Parameter description: Specifies the cost limit. The vacuum thread will hibernate if this limit is exceeded. When the execution cost of the VACUUM thread reaches vacuum_cost_limit, the thread sleeps for the time specified by vacuum_cost_delay. This parameter can be set at the PDB level.
Parameter type: Integer
Unit: None
Value range: 1 to 10000
Default value: 1000. In the PDB scenario, if this parameter is not set, the global settings will apply.
Setting method: This is a USERSET parameter. Set it based on instructions provided in Table 1.
Setting suggestion: Retain the default value. A larger value indicates a smaller I/O frequency limit of the VACUUM, a lower probability of entering the hibernation, more efficient VACUUM, and a greater impact on service I/Os.
Risks and impacts of improper settings: Change the parameter value after fully understanding the parameter meaning and verifying it through testing.
vacuum_defer_cleanup_age
Parameter description: Specifies the delay for the VACUUM operation to clear invalid row-store table records. The delay is calculated based on the number of executed transactions. You can set the value of vacuum_defer_cleanup_age to control the number of delayed transactions. That is, the VACUUM and VACUUM FULL operations do not clear a deleted tuple immediately. Instead, they clear and delete the tuple only after a certain number of transactions have been processed.
Parameter type: Integer
Unit: None
Value range: 0 to 1000000. 0 indicates no delay.
Default value: 0
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: If the value is too large, VACUUM and VACUUM FULL cannot be performed in a timely manner.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot