跳转到主要内容

pg_living_assertions

保存可执行 SQL 检查、核验日期和断言变更历史

概览

扩展包名版本分类许可证语言
pg_living_assertions0.5.1ADMINPostgreSQLSQL
ID扩展名BinLibLoadCreateTrustReloc模式
5300pg_living_assertions否否否是否否living_assertions
相关扩展
下游依赖pg_grammar_guard

On-demand SQL checks run in a read-only subtransaction that is always rolled back; not per-write SQL ASSERTION constraints.

版本

类型仓库版本PG 大版本包名依赖
EXTPIGSTY0.5.11817161514pg_living_assertions-
RPMPIGSTY0.5.11817161514pg_living_assertions_$v-
DEBPIGSTY0.5.11817161514postgresql-$v-pg-living-assertions-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
el8.aarch64
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
el9.x86_64
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
el9.aarch64
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
el10.x86_64
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
el10.aarch64
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
d12.x86_64
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
d12.aarch64
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
d13.x86_64
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
d13.aarch64
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
u22.x86_64
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
u22.aarch64
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
u24.x86_64
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
u24.aarch64
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
u26.x86_64
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
u26.aarch64
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1
PIGSTY 0.5.1

构建

您可以使用 pig build 命令构建 pg_living_assertions 扩展的 RPM / DEB 包:

pig build pkg pg_living_assertions         # 构建 RPM / DEB 包

安装

您可以直接安装 pg_living_assertions 扩展包的预置二进制包,首先确保 PGDG 和 PIGSTY 仓库已经添加并启用:

pig repo add pgsql -u          # 添加仓库并更新缓存

使用 pig 或者是 apt/yum/dnf 安装扩展:

安装
pig install pg_living_assertions;          # 当前活跃 PG 版本安装
pig
pig ext install -y pg_living_assertions -v 18  # PG 18
pig ext install -y pg_living_assertions -v 17  # PG 17
pig ext install -y pg_living_assertions -v 16  # PG 16
pig ext install -y pg_living_assertions -v 15  # PG 15
pig ext install -y pg_living_assertions -v 14  # PG 14
dnf
dnf install -y pg_living_assertions_18       # PG 18
dnf install -y pg_living_assertions_17       # PG 17
dnf install -y pg_living_assertions_16       # PG 16
dnf install -y pg_living_assertions_15       # PG 15
dnf install -y pg_living_assertions_14       # PG 14
apt
apt install -y postgresql-18-pg-living-assertions   # PG 18
apt install -y postgresql-17-pg-living-assertions   # PG 17
apt install -y postgresql-16-pg-living-assertions   # PG 16
apt install -y postgresql-15-pg-living-assertions   # PG 15
apt install -y postgresql-14-pg-living-assertions   # PG 14

创建扩展:

CREATE EXTENSION pg_living_assertions;

用法

来源:

pg_living_assertions 0.5.1 保存 SQL 检查、结论、核验时间与替换历史。检查按需运行,并非每次写入都求值的 SQL ASSERTION 约束。此扩展为纯 SQL 实现,无需预加载。

注册与核验

CREATE EXTENSION pg_living_assertions;
SELECT living_assertions.declare(
  'simple_check', 'one equals one',
  $$SELECT 1 = 1 AS holds, 'arithmetic check'::text AS detail$$);
SELECT living_assertions.run('simple_check');
SELECT name, state, age FROM living_assertions.status;

结果与历史

每个检查必须返回恰好一行,包含布尔列 holds 和可选文本列 detail。living_assertions.run_all() 执行已注册检查。living_assertions.state() 区分成立、失效、未知、报错、未检查、已退役与未注册;living_assertions.stale() 区分从未检查与结果过期。living_assertions.declare_unchanged() 保存表达式以供后续文本比较,因此作者必须自行规范化输出。定义通过附带原因的替换保留历史,结果与注册表数据包含在数据库备份中。

执行与权限

从 0.5.0 起,求值器以只读方式在始终回滚的子事务中执行,并保留检查结论。这修复了旧求值器仅依赖 STABLE、无法阻止易变函数副作用的问题。它不是不可信 SQL 的沙箱:临时序列变更、会话级咨询锁与外部副作用仍可能保留。仅应授权可信管理员注册检查;检查使用后续调用者的权限执行。注册表属于扩展所有者,写入函数默认撤销 PUBLIC 执行权限。

升级

安装匹配的文件后,执行 ALTER EXTENSION pg_living_assertions UPDATE TO '0.5.1'。0.4.1→0.5.0→0.5.1 升级链替换求值函数,不修改注册表结构。最后的补丁在 run() 中限定行类型名称,防止类型缓存失效后在断言自身的无关搜索路径中重新解析类型。

全新安装也使用较早的基础 SQL 脚本并依次应用包内升级链,因此必须安装完整且版本匹配的脚本集。

这个页面对您有帮助吗?