PostgreSQL 18 preview - 新增GUC: vacuum_truncate 垃圾回收时是否收截断表的末尾空页
PostgreSQL 18 preview - 新增GUC: vacuum_truncate 控制垃圾回收时是否收缩文件大小(截断表的末尾空页)
PostgreSQL 18 新增GUC: vacuum_truncate 控制垃圾回收时是否收缩文件大小(截断表的末尾空页). 注意修改文件大小涉及修改inode, 同时也可能引起向standby 发送锁请求导致冲突和等待. 所以vacuum_truncate参数可以用来控制该行为, 是否要截断.
vacuum_truncate 的设置可以被表级别的存储参数 (storage parameter) 或者 VACUUM 命令的 TRUNCATE 选项覆盖。
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=0164a0f9ee12e0eff9e4c661358a272ecd65c2d4
Add vacuum_truncate configuration parameter.
author Nathan Bossart <[email protected]>
Thu, 20 Mar 2025 15:16:50 +0000 (10:16 -0500)
committer Nathan Bossart <[email protected]>
Thu, 20 Mar 2025 15:16:50 +0000 (10:16 -0500)
commit 0164a0f9ee12e0eff9e4c661358a272ecd65c2d4
tree adc03a29d38053e20cf598d579a8717f16b21212 tree
parent 618c64ffd3967cb5313b4b11e1e1043a074f2139 commit | diff
Add vacuum_truncate configuration parameter.
This new parameter works just like the storage parameter of the
same name: ifset to true (which is the default), autovacuum and
VACUUM attempt to truncate any empty pages at the end of the table.
It is primarily intended to help users avoid locking issues on hot
standbys. The setting can be overridden with the storage parameter
or VACUUM's TRUNCATE option.
Since there's presently no way to determine whether a Boolean
storage parameter is explicitly set or has just picked up the
default value, this commit also introduces an isset_offset member
to relopt_parse_elt.
Suggested-by: Will Storey <[email protected]>
Author: Nathan Bossart <[email protected]>
Co-authored-by: Gurjeet Singh <[email protected]>
Reviewed-by: Laurenz Albe <[email protected]>
Reviewed-by: Fujii Masao <[email protected]>
Reviewed-by: Robert Treat <[email protected]>
Discussion: https://postgr.es/m/Z2DE4lDX4tHqNGZt%40dev.null
AI 解读
这个patch引入了一个新的配置参数 vacuum_truncate。
主要功能:
vacuum_truncate参数控制autovacuum(自动清理) 和VACUUM命令是否尝试截断表末尾的空页。默认情况下, vacuum_truncate设置为true,意味着autovacuum和VACUUM会尝试截断空页。这个参数的主要目的是帮助用户避免在热备机(hot standby)上出现锁定问题。截断空页可能会导致一些锁定,在热备机上可能会造成问题。 vacuum_truncate的设置可以被表级别的存储参数 (storage parameter) 或者VACUUM命令的TRUNCATE选项覆盖。
技术细节:
由于目前无法区分一个布尔类型的存储参数是显式设置的还是仅仅使用了默认值,这个patch还引入了一个新的成员 isset_offset到relopt_parse_elt结构体中。relopt_parse_elt结构体用于解析关系选项(relation options),例如存储参数。isset_offset成员用于跟踪该参数是否被显式设置。
总结:
这个patch增加了一个新的配置参数 vacuum_truncate,用于控制 autovacuum 和 VACUUM 是否截断表末尾的空页。 这个参数的主要目的是为了解决热备机上的锁定问题,并且可以被表级别的存储参数或 VACUUM 命令的选项覆盖。 为了实现这个功能,patch还修改了 relopt_parse_elt 结构体,增加了一个成员用于跟踪参数是否被显式设置。
贡献者:
建议者:Will Storey 作者:Nathan Bossart 共同作者:Gurjeet Singh 审核者:Laurenz Albe, Fujii Masao, Robert Treat
讨论链接:
https://postgr.es/m/Z2DE4lDX4tHqNGZt%40dev.null