跳转到主要内容

pg_living_assertions

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

概览

扩展包名版本分类许可证语言
pg_living_assertions0.5.10ADMINApache-2.0SQL
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.101817161514pg_living_assertions-
RPMPIGSTY0.5.101817161514pg_living_assertions_$v-
DEBPIGSTY0.5.101817161514postgresql-$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.10 保存具名 SQL 断言、结果与替换历史。检查按需运行,并非每次写入都执行的约束。这是无需预加载的纯 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.status 和 living_assertions.stale() 区分失效、未知、报错,以及过期或未执行的检查。living_assertions.declare_unchanged() 对规范化表达式计算指纹,原有值变成 NULL 时判为失效。检查以记录的作者身份,在只读且回滚的子事务中执行,采用作者搜索路径并将临时模式放在最后。调用者须有权 SET ROLE 到该作者。求值时取得的会话咨询锁会被释放,但外部副作用和临时序列变化不在沙箱控制范围内,只有可信作者应登记 SQL。注册和检查时间由服务器确定,表拒绝 TRUNCATE,退役与替换仅限作者或有权代理的角色。升级须安装完整匹配的 SQL 链;旧断言保留原有指纹算法。当前版本采用 Apache-2.0,截至 0.5.3 的已发布版本仍保留原来的 PostgreSQL License。

0.5.10 的角色隔离

0.5.10 在需要角色隔离时,将检查放入由记录作者拥有的临时 SECURITY DEFINER 函数。PostgreSQL 会拒绝在该执行环境中重置角色或会话授权;函数与只读检查在同一子事务中创建并回滚。需要该执行环境时,作者必须拥有数据库的 TEMP 权限,调用者仍须有权代理该作者。SECURITY DEFINER 调用者现可凭此权限执行其他作者的检查。这修复了 0.5.8/0.5.9 中重置角色的逃逸路径,但不会使外部副作用变得安全。

这个页面对您有帮助吗?