今天PostgreSQL全球开发组发布18 Beta2,本文重点关注Beta2版本相比Beta1版本的增量变化,解读如下:
- Revert “Don’t lock partitions pruned by initial pruning”
分区表的一个锁优化特性,测试有bug,被回退。
- Revert function to get memory context stats for processes
可观测其它会话内存使用情况的一个函数,测试有内存泄漏,被回退。

- 异步读IO视图pg_aios的operation字段发生调整
operation字段使用readv/writev值替代read/write,与内核代码术语保持一致。

- pg_dump及pg_dumpall工具默认是否导出统计信息发生变化
以往大版本升级使用pg_upgrade工具,需要先检查新旧版本兼容性,再正式升级新版本,升级完成之后还有一步非常重要的工具就是手工更新统计信息,新版本pg_upgrade会自动帮我们保留统计信息。

保留统计信息的优化也伴生应用到pg_dump及pg_dumpall工具,不过pg_dump及pg_dumpall工具被用户自行使用(非系统调用)时默认不处理统计信息,而pg_restore及pg_upgrade工具默认保留统计信息。
详细使用请参考工具的–no-statistics、–with-statistics选项。
- 重命名log_lock_failure参数为log_lock_failures
使用复数形式与log_lock_waits参数保持一致性命名风格。
- pg_maintain新增几个统计信息维护函数的操作权限

- 重新定义pg_class系统表的reltuples字段默认值
用户表未执行VACUUM或者ANALYZE操作之前,reltuples值定义为-1,有维护操作之后表数据为空reltuples值才为0。
CREATE TABLE tab1 (id int);
SELECT reltuples FROM pg_class WHERE relname ='tab1';
reltuples
-----------
-1
(1 row)
VACUUM tab1;
SELECT reltuples FROM pg_class WHERE relname ='tab1';
reltuples
-----------
0
(1 row)
- 延迟执行的触发器以实际触发的角色运行
官方文档进行了补充描述:
Run each deferred trigger as the role that caused the trigger to fire
Also, the trigger will always run in the security context of the role that executed the statement that caused the trigger to fire, unless the trigger function is defined as SECURITY DEFINER,in which case it will run as the function owner.
- psql元命令
\conninfo输出微调:显示完整的客户端协议版本,例如3.0或者3.2,TLS显示改为SSL。
\close关闭预编译语句重命名为 \close_prepared,
- 复制槽超时参数idle_replication_slot_timeout默认值变化
新版本增加的idle_replication_slot_timeout可以对长时间不使用的逻辑复制槽进行失效处理来避免WAL不回收的问题,不过参数的单位默认变为秒,之前设计为分钟不太合理。
参考链接:
https://www.postgresql.org/about/news/postgresql-18-beta-2-released-3103
https://momjian.us/main/writings/pgsql/features.pdf
推荐阅读
PG 18beta1 真正的AIO来了|发展历程&测试
PG 18beta1 真正的AIO来了|感慨&环境准备
PG 18beta1 今日发布




