跳转到主要内容

pg_disorder

扰动无 ORDER BY 查询的行序以暴露依赖隐式顺序的测试

pg_disorder · 扰动无 ORDER BY 查询的行序以暴露依赖隐式顺序的测试

概览

ID扩展软件包版本类别许可证编程语言
2880pg_disorderpg_disorder0.1.0FEATPostgreSQLC
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--sL---否是是否否否
Headless loadable module with no control file and no CREATE EXTENSION step; intended only for test databases; load per session with session_preload_libraries and never enable globally in production.

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY0.1.019 18 17 16 15pg_disorder-
RPMPIGSTY0.1.019 18 17 16 15pg_disorder_$v-
DEBPIGSTY0.1.019 18 17 16 15postgresql-$v-pg-disorder-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
el8.aarch64N/APIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
el9.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
el9.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
el10.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
el10.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
d12.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
d12.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
d13.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
d13.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
u22.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
u22.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
u24.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
u24.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
u26.x86_64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
u26.aarch64PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0PIGSTY 0.1.0
软件包版本平台仓库大小下载
pg_disorder_190.1.0el9.x86_64pigsty30.1 KiBpg_disorder_19-0.1.0-1PGSTY.el9.x86_64.rpm
pg_disorder_190.1.0el9.aarch64pigsty29.9 KiBpg_disorder_19-0.1.0-1PGSTY.el9.aarch64.rpm
pg_disorder_190.1.0el10.x86_64pigsty30.3 KiBpg_disorder_19-0.1.0-1PGSTY.el10.x86_64.rpm
pg_disorder_190.1.0el10.aarch64pigsty30.2 KiBpg_disorder_19-0.1.0-1PGSTY.el10.aarch64.rpm
postgresql-19-pg-disorder0.1.0d12.x86_64pigsty21.5 KiBpostgresql-19-pg-disorder_0.1.0-1PGSTY~bookworm_amd64.deb
postgresql-19-pg-disorder0.1.0d12.aarch64pigsty21.2 KiBpostgresql-19-pg-disorder_0.1.0-1PGSTY~bookworm_arm64.deb
postgresql-19-pg-disorder0.1.0d13.x86_64pigsty21.5 KiBpostgresql-19-pg-disorder_0.1.0-1PGSTY~trixie_amd64.deb
postgresql-19-pg-disorder0.1.0d13.aarch64pigsty21.3 KiBpostgresql-19-pg-disorder_0.1.0-1PGSTY~trixie_arm64.deb
postgresql-19-pg-disorder0.1.0u22.x86_64pigsty22.3 KiBpostgresql-19-pg-disorder_0.1.0-1PGSTY~jammy_amd64.deb
postgresql-19-pg-disorder0.1.0u22.aarch64pigsty22.2 KiBpostgresql-19-pg-disorder_0.1.0-1PGSTY~jammy_arm64.deb
postgresql-19-pg-disorder0.1.0u24.x86_64pigsty22.3 KiBpostgresql-19-pg-disorder_0.1.0-1PGSTY~noble_amd64.deb
postgresql-19-pg-disorder0.1.0u24.aarch64pigsty22.2 KiBpostgresql-19-pg-disorder_0.1.0-1PGSTY~noble_arm64.deb
postgresql-19-pg-disorder0.1.0u26.x86_64pigsty22.3 KiBpostgresql-19-pg-disorder_0.1.0-1PGSTY~resolute_amd64.deb
postgresql-19-pg-disorder0.1.0u26.aarch64pigsty22.0 KiBpostgresql-19-pg-disorder_0.1.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_disorder_180.1.0el8.x86_64pigsty29.6 KiBpg_disorder_18-0.1.0-1PGSTY.el8.x86_64.rpm
pg_disorder_180.1.0el8.aarch64pigsty29.3 KiBpg_disorder_18-0.1.0-1PGSTY.el8.aarch64.rpm
pg_disorder_180.1.0el9.x86_64pigsty30.1 KiBpg_disorder_18-0.1.0-1PGSTY.el9.x86_64.rpm
pg_disorder_180.1.0el9.aarch64pigsty29.8 KiBpg_disorder_18-0.1.0-1PGSTY.el9.aarch64.rpm
pg_disorder_180.1.0el10.x86_64pigsty30.3 KiBpg_disorder_18-0.1.0-1PGSTY.el10.x86_64.rpm
pg_disorder_180.1.0el10.aarch64pigsty30.1 KiBpg_disorder_18-0.1.0-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-disorder0.1.0d12.x86_64pigsty21.4 KiBpostgresql-18-pg-disorder_0.1.0-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-disorder0.1.0d12.aarch64pigsty21.2 KiBpostgresql-18-pg-disorder_0.1.0-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-disorder0.1.0d13.x86_64pigsty21.5 KiBpostgresql-18-pg-disorder_0.1.0-1PGSTY~trixie_amd64.deb
postgresql-18-pg-disorder0.1.0d13.aarch64pigsty21.2 KiBpostgresql-18-pg-disorder_0.1.0-1PGSTY~trixie_arm64.deb
postgresql-18-pg-disorder0.1.0u22.x86_64pigsty22.3 KiBpostgresql-18-pg-disorder_0.1.0-1PGSTY~jammy_amd64.deb
postgresql-18-pg-disorder0.1.0u22.aarch64pigsty22.2 KiBpostgresql-18-pg-disorder_0.1.0-1PGSTY~jammy_arm64.deb
postgresql-18-pg-disorder0.1.0u24.x86_64pigsty22.3 KiBpostgresql-18-pg-disorder_0.1.0-1PGSTY~noble_amd64.deb
postgresql-18-pg-disorder0.1.0u24.aarch64pigsty22.1 KiBpostgresql-18-pg-disorder_0.1.0-1PGSTY~noble_arm64.deb
postgresql-18-pg-disorder0.1.0u26.x86_64pigsty22.3 KiBpostgresql-18-pg-disorder_0.1.0-1PGSTY~resolute_amd64.deb
postgresql-18-pg-disorder0.1.0u26.aarch64pigsty22.0 KiBpostgresql-18-pg-disorder_0.1.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_disorder_170.1.0el8.x86_64pigsty29.6 KiBpg_disorder_17-0.1.0-1PGSTY.el8.x86_64.rpm
pg_disorder_170.1.0el8.aarch64pigsty29.4 KiBpg_disorder_17-0.1.0-1PGSTY.el8.aarch64.rpm
pg_disorder_170.1.0el9.x86_64pigsty30.3 KiBpg_disorder_17-0.1.0-1PGSTY.el9.x86_64.rpm
pg_disorder_170.1.0el9.aarch64pigsty29.8 KiBpg_disorder_17-0.1.0-1PGSTY.el9.aarch64.rpm
pg_disorder_170.1.0el10.x86_64pigsty30.3 KiBpg_disorder_17-0.1.0-1PGSTY.el10.x86_64.rpm
pg_disorder_170.1.0el10.aarch64pigsty30.2 KiBpg_disorder_17-0.1.0-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-disorder0.1.0d12.x86_64pigsty21.3 KiBpostgresql-17-pg-disorder_0.1.0-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-disorder0.1.0d12.aarch64pigsty21.2 KiBpostgresql-17-pg-disorder_0.1.0-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-disorder0.1.0d13.x86_64pigsty21.3 KiBpostgresql-17-pg-disorder_0.1.0-1PGSTY~trixie_amd64.deb
postgresql-17-pg-disorder0.1.0d13.aarch64pigsty21.2 KiBpostgresql-17-pg-disorder_0.1.0-1PGSTY~trixie_arm64.deb
postgresql-17-pg-disorder0.1.0u22.x86_64pigsty25.2 KiBpostgresql-17-pg-disorder_0.1.0-1PGSTY~jammy_amd64.deb
postgresql-17-pg-disorder0.1.0u22.aarch64pigsty24.8 KiBpostgresql-17-pg-disorder_0.1.0-1PGSTY~jammy_arm64.deb
postgresql-17-pg-disorder0.1.0u24.x86_64pigsty22.2 KiBpostgresql-17-pg-disorder_0.1.0-1PGSTY~noble_amd64.deb
postgresql-17-pg-disorder0.1.0u24.aarch64pigsty22.1 KiBpostgresql-17-pg-disorder_0.1.0-1PGSTY~noble_arm64.deb
postgresql-17-pg-disorder0.1.0u26.x86_64pigsty22.3 KiBpostgresql-17-pg-disorder_0.1.0-1PGSTY~resolute_amd64.deb
postgresql-17-pg-disorder0.1.0u26.aarch64pigsty22.0 KiBpostgresql-17-pg-disorder_0.1.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_disorder_160.1.0el8.x86_64pigsty29.7 KiBpg_disorder_16-0.1.0-1PGSTY.el8.x86_64.rpm
pg_disorder_160.1.0el8.aarch64pigsty29.5 KiBpg_disorder_16-0.1.0-1PGSTY.el8.aarch64.rpm
pg_disorder_160.1.0el9.x86_64pigsty30.4 KiBpg_disorder_16-0.1.0-1PGSTY.el9.x86_64.rpm
pg_disorder_160.1.0el9.aarch64pigsty30.0 KiBpg_disorder_16-0.1.0-1PGSTY.el9.aarch64.rpm
pg_disorder_160.1.0el10.x86_64pigsty30.4 KiBpg_disorder_16-0.1.0-1PGSTY.el10.x86_64.rpm
pg_disorder_160.1.0el10.aarch64pigsty30.3 KiBpg_disorder_16-0.1.0-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-disorder0.1.0d12.x86_64pigsty21.4 KiBpostgresql-16-pg-disorder_0.1.0-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-disorder0.1.0d12.aarch64pigsty21.3 KiBpostgresql-16-pg-disorder_0.1.0-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-disorder0.1.0d13.x86_64pigsty21.4 KiBpostgresql-16-pg-disorder_0.1.0-1PGSTY~trixie_amd64.deb
postgresql-16-pg-disorder0.1.0d13.aarch64pigsty21.4 KiBpostgresql-16-pg-disorder_0.1.0-1PGSTY~trixie_arm64.deb
postgresql-16-pg-disorder0.1.0u22.x86_64pigsty25.2 KiBpostgresql-16-pg-disorder_0.1.0-1PGSTY~jammy_amd64.deb
postgresql-16-pg-disorder0.1.0u22.aarch64pigsty24.9 KiBpostgresql-16-pg-disorder_0.1.0-1PGSTY~jammy_arm64.deb
postgresql-16-pg-disorder0.1.0u24.x86_64pigsty22.3 KiBpostgresql-16-pg-disorder_0.1.0-1PGSTY~noble_amd64.deb
postgresql-16-pg-disorder0.1.0u24.aarch64pigsty22.2 KiBpostgresql-16-pg-disorder_0.1.0-1PGSTY~noble_arm64.deb
postgresql-16-pg-disorder0.1.0u26.x86_64pigsty22.5 KiBpostgresql-16-pg-disorder_0.1.0-1PGSTY~resolute_amd64.deb
postgresql-16-pg-disorder0.1.0u26.aarch64pigsty22.1 KiBpostgresql-16-pg-disorder_0.1.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_disorder_150.1.0el8.x86_64pigsty29.7 KiBpg_disorder_15-0.1.0-1PGSTY.el8.x86_64.rpm
pg_disorder_150.1.0el8.aarch64pigsty29.5 KiBpg_disorder_15-0.1.0-1PGSTY.el8.aarch64.rpm
pg_disorder_150.1.0el9.x86_64pigsty30.4 KiBpg_disorder_15-0.1.0-1PGSTY.el9.x86_64.rpm
pg_disorder_150.1.0el9.aarch64pigsty30.0 KiBpg_disorder_15-0.1.0-1PGSTY.el9.aarch64.rpm
pg_disorder_150.1.0el10.x86_64pigsty30.4 KiBpg_disorder_15-0.1.0-1PGSTY.el10.x86_64.rpm
pg_disorder_150.1.0el10.aarch64pigsty30.3 KiBpg_disorder_15-0.1.0-1PGSTY.el10.aarch64.rpm
postgresql-15-pg-disorder0.1.0d12.x86_64pigsty21.4 KiBpostgresql-15-pg-disorder_0.1.0-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-disorder0.1.0d12.aarch64pigsty21.3 KiBpostgresql-15-pg-disorder_0.1.0-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-disorder0.1.0d13.x86_64pigsty21.4 KiBpostgresql-15-pg-disorder_0.1.0-1PGSTY~trixie_amd64.deb
postgresql-15-pg-disorder0.1.0d13.aarch64pigsty21.4 KiBpostgresql-15-pg-disorder_0.1.0-1PGSTY~trixie_arm64.deb
postgresql-15-pg-disorder0.1.0u22.x86_64pigsty25.2 KiBpostgresql-15-pg-disorder_0.1.0-1PGSTY~jammy_amd64.deb
postgresql-15-pg-disorder0.1.0u22.aarch64pigsty24.9 KiBpostgresql-15-pg-disorder_0.1.0-1PGSTY~jammy_arm64.deb
postgresql-15-pg-disorder0.1.0u24.x86_64pigsty22.3 KiBpostgresql-15-pg-disorder_0.1.0-1PGSTY~noble_amd64.deb
postgresql-15-pg-disorder0.1.0u24.aarch64pigsty22.3 KiBpostgresql-15-pg-disorder_0.1.0-1PGSTY~noble_arm64.deb
postgresql-15-pg-disorder0.1.0u26.x86_64pigsty22.5 KiBpostgresql-15-pg-disorder_0.1.0-1PGSTY~resolute_amd64.deb
postgresql-15-pg-disorder0.1.0u26.aarch64pigsty22.1 KiBpostgresql-15-pg-disorder_0.1.0-1PGSTY~resolute_arm64.deb

源码

pig build pkg pg_disorder;		# build rpm/deb

安装

启用 PGDG 和 PIGSTY 仓库并更新缓存。

pig repo add pgsql -u   # add both repo and update cache

使用 pig 安装扩展。

pig install pg_disorder;		# install by package name

pig install pg_disorder -v 19;   # install for PG 19
pig install pg_disorder -v 18;   # install for PG 18
pig install pg_disorder -v 17;   # install for PG 17
pig install pg_disorder -v 16;   # install for PG 16
pig install pg_disorder -v 15;   # install for PG 15

将扩展加入 shared_preload_libraries,详见配置说明。

shared_preload_libraries = 'pg_disorder';

此扩展无需执行 CREATE EXTENSION。

用法

来源:

pg_disorder 是一个仅用于测试的 PostgreSQL 可加载模块,它会有意改变符合条件的 SELECT 查询输出顺序,用于发现无意中依赖未指定行顺序的应用和测试。它是一个无扩展对象的模块:没有控制文件、SQL 安装脚本,也不需要执行 CREATE EXTENSION pg_disorder。

为测试数据库启用

在会话启动时加载该模块,以便其规划器钩子可用:

ALTER DATABASE regression_db
  SET session_preload_libraries = 'pg_disorder';

ALTER DATABASE regression_db
  SET pg_disorder.mode = 'reverse';

修改 session_preload_libraries 后应重新连接。不要将此模块加入生产环境全局的 shared_preload_libraries 设置。

模式

SET pg_disorder.mode = 'off';
SET pg_disorder.mode = 'reverse';
SET pg_disorder.mode = 'shuffle';
SET pg_disorder.seed = 42;
SET pg_disorder.force_serial = on;
  • off 不改变执行计划。
  • reverse 以确定性方式反转符合条件的输出。
  • shuffle 在会话种子、提交的查询文本和执行计划固定时产生确定性排列。使用默认种子零时,每个会话会先选择并记录一个随机种子。
  • force_serial 禁止并行计划,使乱序测试能够复现。

修复失败查询时,应添加语义正确的 ORDER BY;不要编码在 off 模式下偶然观察到的顺序。

适用条件与注意事项

该钩子面向没有 ORDER BY 的顶层 SELECT 语句。它会有意跳过那些重新排序不安全或会改变 SQL 语义的查询形态,包括聚合、分组、DISTINCT、集合操作、窗口函数、递归查询、行锁,以及没有 FROM 关系的查询。

  • pg_disorder 是故障注入工具,而不是生产查询功能。
  • 乱序测试通过并不能证明每个无序查询都安全;被排除的查询形态和规划器路径不会被重写。
  • 软件包仅安装服务器模块。应通过 GUC 或模块加载状态验证是否启用,而不是查看 pg_extension。

表格阅读器