跳转到主要内容

pg_auditor

审计数据变更并提供闪回能力

pg_auditor · 审计数据变更并提供闪回能力

概览

ID扩展软件包版本类别许可证编程语言
7130pg_auditorpg_auditor0.3SECBSD-3-ClauseSQL
属性可执行文件动态库需要预加载需要建扩展可迁移可信
----d--否否否是否否

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY0.319 18 17 16 15pg_auditorhstore
RPMPIGSTY0.3.019 18 17 16 15pg_auditor_$v-
DEBPIGSTY0.3.019 18 17 16 15postgresql-$v-pg-auditor-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.3PIGSTY 0.3PIGSTY 0.3PIGSTY 0.3
el8.aarch64N/APIGSTY 0.3PIGSTY 0.3PIGSTY 0.3PIGSTY 0.3
el9.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
el9.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
el10.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
el10.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
d12.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
d12.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
d13.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
d13.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
u22.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
u22.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
u24.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
u24.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
u26.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
u26.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
软件包版本平台仓库大小下载
pg_auditor_190.3.0el9.x86_64pigsty14.7 KiBpg_auditor_19-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_190.3.0el9.aarch64pigsty14.7 KiBpg_auditor_19-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_190.3.0el10.x86_64pigsty14.8 KiBpg_auditor_19-0.3.0-1PGSTY.el10.noarch.rpm
pg_auditor_190.3.0el10.aarch64pigsty14.8 KiBpg_auditor_19-0.3.0-1PGSTY.el10.noarch.rpm
postgresql-19-pg-auditor0.3.0d12.x86_64pigsty8.7 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-19-pg-auditor0.3.0d12.aarch64pigsty8.7 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-19-pg-auditor0.3.0d13.x86_64pigsty8.7 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-19-pg-auditor0.3.0d13.aarch64pigsty8.7 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-19-pg-auditor0.3.0u22.x86_64pigsty8.5 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-19-pg-auditor0.3.0u22.aarch64pigsty8.5 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-19-pg-auditor0.3.0u24.x86_64pigsty8.5 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-19-pg-auditor0.3.0u24.aarch64pigsty8.5 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-19-pg-auditor0.3.0u26.x86_64pigsty8.5 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~resolute_all.deb
postgresql-19-pg-auditor0.3.0u26.aarch64pigsty8.5 KiBpostgresql-19-pg-auditor_0.3.0-1PGSTY~resolute_all.deb
软件包版本平台仓库大小下载
pg_auditor_180.3el8.x86_64pigsty14.8 KiBpg_auditor_18-0.3-1.git20250228.7c2edffPGSTY.el8.noarch.rpm
pg_auditor_180.3el8.aarch64pigsty14.8 KiBpg_auditor_18-0.3-1.git20250228.7c2edffPGSTY.el8.noarch.rpm
pg_auditor_180.3.0el9.x86_64pigsty14.7 KiBpg_auditor_18-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_180.3.0el9.aarch64pigsty14.7 KiBpg_auditor_18-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_180.3.0el10.x86_64pigsty14.8 KiBpg_auditor_18-0.3.0-1PGSTY.el10.noarch.rpm
pg_auditor_180.3.0el10.aarch64pigsty14.8 KiBpg_auditor_18-0.3.0-1PGSTY.el10.noarch.rpm
postgresql-18-pg-auditor0.3.0d12.x86_64pigsty8.7 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-18-pg-auditor0.3.0d12.aarch64pigsty8.7 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-18-pg-auditor0.3.0d13.x86_64pigsty8.7 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-18-pg-auditor0.3.0d13.aarch64pigsty8.7 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-18-pg-auditor0.3.0u22.x86_64pigsty8.5 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-18-pg-auditor0.3.0u22.aarch64pigsty8.5 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-18-pg-auditor0.3.0u24.x86_64pigsty8.5 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-18-pg-auditor0.3.0u24.aarch64pigsty8.5 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-18-pg-auditor0.3.0u26.x86_64pigsty8.5 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~resolute_all.deb
postgresql-18-pg-auditor0.3.0u26.aarch64pigsty8.5 KiBpostgresql-18-pg-auditor_0.3.0-1PGSTY~resolute_all.deb
软件包版本平台仓库大小下载
pg_auditor_170.3el8.x86_64pigsty14.8 KiBpg_auditor_17-0.3-1.git20250228.7c2edffPGSTY.el8.noarch.rpm
pg_auditor_170.3el8.aarch64pigsty14.8 KiBpg_auditor_17-0.3-1.git20250228.7c2edffPGSTY.el8.noarch.rpm
pg_auditor_170.3.0el9.x86_64pigsty14.7 KiBpg_auditor_17-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_170.3.0el9.aarch64pigsty14.7 KiBpg_auditor_17-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_170.3.0el10.x86_64pigsty14.8 KiBpg_auditor_17-0.3.0-1PGSTY.el10.noarch.rpm
pg_auditor_170.3.0el10.aarch64pigsty14.8 KiBpg_auditor_17-0.3.0-1PGSTY.el10.noarch.rpm
postgresql-17-pg-auditor0.3.0d12.x86_64pigsty8.7 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-17-pg-auditor0.3.0d12.aarch64pigsty8.7 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-17-pg-auditor0.3.0d13.x86_64pigsty8.7 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-17-pg-auditor0.3.0d13.aarch64pigsty8.7 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-17-pg-auditor0.3.0u22.x86_64pigsty8.5 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-17-pg-auditor0.3.0u22.aarch64pigsty8.5 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-17-pg-auditor0.3.0u24.x86_64pigsty8.5 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-17-pg-auditor0.3.0u24.aarch64pigsty8.5 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-17-pg-auditor0.3.0u26.x86_64pigsty8.5 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~resolute_all.deb
postgresql-17-pg-auditor0.3.0u26.aarch64pigsty8.5 KiBpostgresql-17-pg-auditor_0.3.0-1PGSTY~resolute_all.deb
软件包版本平台仓库大小下载
pg_auditor_160.3el8.x86_64pigsty14.8 KiBpg_auditor_16-0.3-1.git20250228.7c2edffPGSTY.el8.noarch.rpm
pg_auditor_160.3el8.aarch64pigsty14.8 KiBpg_auditor_16-0.3-1.git20250228.7c2edffPGSTY.el8.noarch.rpm
pg_auditor_160.3.0el9.x86_64pigsty14.7 KiBpg_auditor_16-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_160.3.0el9.aarch64pigsty14.7 KiBpg_auditor_16-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_160.3.0el10.x86_64pigsty14.8 KiBpg_auditor_16-0.3.0-1PGSTY.el10.noarch.rpm
pg_auditor_160.3.0el10.aarch64pigsty14.8 KiBpg_auditor_16-0.3.0-1PGSTY.el10.noarch.rpm
postgresql-16-pg-auditor0.3.0d12.x86_64pigsty8.7 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-16-pg-auditor0.3.0d12.aarch64pigsty8.7 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-16-pg-auditor0.3.0d13.x86_64pigsty8.7 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-16-pg-auditor0.3.0d13.aarch64pigsty8.7 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-16-pg-auditor0.3.0u22.x86_64pigsty8.5 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-16-pg-auditor0.3.0u22.aarch64pigsty8.5 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-16-pg-auditor0.3.0u24.x86_64pigsty8.5 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-16-pg-auditor0.3.0u24.aarch64pigsty8.5 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-16-pg-auditor0.3.0u26.x86_64pigsty8.5 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~resolute_all.deb
postgresql-16-pg-auditor0.3.0u26.aarch64pigsty8.5 KiBpostgresql-16-pg-auditor_0.3.0-1PGSTY~resolute_all.deb
软件包版本平台仓库大小下载
pg_auditor_150.3el8.x86_64pigsty14.8 KiBpg_auditor_15-0.3-1.git20250228.7c2edffPGSTY.el8.noarch.rpm
pg_auditor_150.3el8.aarch64pigsty14.8 KiBpg_auditor_15-0.3-1.git20250228.7c2edffPGSTY.el8.noarch.rpm
pg_auditor_150.3.0el9.x86_64pigsty14.7 KiBpg_auditor_15-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_150.3.0el9.aarch64pigsty14.7 KiBpg_auditor_15-0.3.0-1PGSTY.el9.noarch.rpm
pg_auditor_150.3.0el10.x86_64pigsty14.8 KiBpg_auditor_15-0.3.0-1PGSTY.el10.noarch.rpm
pg_auditor_150.3.0el10.aarch64pigsty14.8 KiBpg_auditor_15-0.3.0-1PGSTY.el10.noarch.rpm
postgresql-15-pg-auditor0.3.0d12.x86_64pigsty8.7 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-15-pg-auditor0.3.0d12.aarch64pigsty8.7 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~bookworm_all.deb
postgresql-15-pg-auditor0.3.0d13.x86_64pigsty8.7 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-15-pg-auditor0.3.0d13.aarch64pigsty8.7 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~trixie_all.deb
postgresql-15-pg-auditor0.3.0u22.x86_64pigsty8.5 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-15-pg-auditor0.3.0u22.aarch64pigsty8.5 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~jammy_all.deb
postgresql-15-pg-auditor0.3.0u24.x86_64pigsty8.5 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-15-pg-auditor0.3.0u24.aarch64pigsty8.5 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~noble_all.deb
postgresql-15-pg-auditor0.3.0u26.x86_64pigsty8.5 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~resolute_all.deb
postgresql-15-pg-auditor0.3.0u26.aarch64pigsty8.5 KiBpostgresql-15-pg-auditor_0.3.0-1PGSTY~resolute_all.deb

源码

pg_auditor-0.3+git20250228.7c2edff.tar.gz

pig build pkg pg_auditor;		# build rpm/deb

安装

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

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

使用 pig 安装扩展。

pig install pg_auditor;		# install by package name

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

在数据库中创建扩展。

CREATE EXTENSION pg_auditor CASCADE; -- requires hstore

用法

pg_auditor: 带闪回功能的数据变更审计

pg_auditor 记录指定表上的每一次数据修改(INSERT、UPDATE、DELETE),并允许部分或完整的事务闪回。

CREATE EXTENSION pg_auditor CASCADE;  -- 同时安装 hstore

审计控制

-- 开始审计一个表(默认审计所有 DML)
SELECT auditor.attach('fruit');

-- 仅审计特定操作
SELECT auditor.attach('fruit', ARRAY['INSERT', 'UPDATE']);

-- 仅审计特定列
SELECT auditor.attach('fruit', ARRAY['INSERT', 'UPDATE', 'DELETE'], ARRAY['name', 'weight']);

-- 停止审计
SELECT auditor.detach('fruit');

-- 管理单个语句/列
SELECT auditor.attach_statement('fruit', 'DELETE');
SELECT auditor.detach_statement('fruit', 'DELETE');
SELECT auditor.attach_column('fruit', 'weight');
SELECT auditor.detach_column('fruit', 'weight');

-- 防止 TRUNCATE
SELECT auditor.forbid_truncate('fruit');

查看审计日志

SELECT transaction_id, operation, old_rec, new_rec FROM auditor.log;

闪回函数

-- 撤销当前会话中最后 N 个事务
SELECT auditor.undo();          -- 撤销最后1个
SELECT auditor.undo(3);         -- 撤销最后3个
SELECT auditor.undo(1, true);   -- 覆盖其他会话

-- 取消特定事务
SELECT auditor.cancel(5557);

-- 将数据恢复到特定事务或时间戳
SELECT auditor.flashback(5556);
SELECT auditor.flashback('2021-02-08 14:40:00'::timestamp);

列演化追踪

SELECT * FROM auditor.evolution('fruit'::regclass, 'weight', 'orange'::text);
-- 显示给定主键的某列值的完整历史

表格阅读器