Record what changed and halt writes先止损并记录误删现场与目标信息
Log the database, schema, table, exact SQL, timestamp, and time zone right away. If the transaction is still open, roll back immediately; once committed, halt writes to preserve the storage state and collect a few known primary keys for reconciliation.
第一时间记录库名、模式名、表名、误删 SQL 及带时区的发生时刻。事务尚未提交时立即执行回滚;若已提交,应马上停止业务写入以保住现场文件,同时整理数条已知主键用于交付验收。
Original section · 对应中文原文
Assess the available recovery path依据现有材料选定恢复路径
Verify first whether an intact base backup and continuous WAL exist. When either link is missing, bypass PITR and preserve the live relation files, system catalogs, and surviving WAL so PDU can decode them directly on a copy.
先确认手头具备的恢复材料:当事故前物理基础备份与连续 WAL 齐全时可走 PITR;一旦缺少任一环节,不宜在无效路径上消耗窗口期,应保留现存表文件、系统目录和残留 WAL,转由 PDU 在只读副本上做底层提取。
Original section · 对应中文原文
PITR belongs on an isolated clone备份链完整时,在隔离实例执行 PITR
When a clean base backup and uninterrupted WAL exist, restore an isolated cluster to the instant before the mistake, extract only the affected rows, and merge them back without overwriting newer legitimate production writes.
物理基础备份与连续 WAL 均完好时,应在独立隔离实例上还原至误操作发生前一秒,单独导出受影响表记录并与生产库合并,避免整库回退覆盖事故后的正常业务写入。
PostgreSQL: continuous archiving and PITROriginal section · 对应中文原文
Never run pg_resetwal for a DELETE切勿用 pg_resetwal 处理误删事件
pg_resetwal rewrites control state to force a broken server up—it never brings back a single deleted row, and running it destroys the exact WAL evidence required for recovery.
pg_resetwal 仅改写集群控制状态并清空原有 WAL,既无法找回任何一行误删数据,还会直接抹除还原所需的日志线索,原盘文件必须保持只读状态。
PostgreSQL: pg_resetwal and its cautionsOriginal section · 对应中文原文
pg_waldump prints raw WAL headers without rebuilding full rows; pg_filedump inspects individual pages; pg_dirtyread requires a running instance and unvacuumed dead tuples. Stitching them together under incident time pressure is slow and error-prone.
pg_waldump 仅输出底层日志记录,pg_filedump 面向单页结构检查,pg_dirtyread 则依赖实例启动与尚未被清理的死元组。紧急场景下手工串联三套工具耗时较长且容易漏掉行外 TOAST 与表结构映射。
Original section · 对应中文原文
Five-step workflow with PDUPDU 五步恢复标准流程
PostgreSQL DUL (PDU) consolidates catalog inspection, WAL scanning, and CSV extraction into a five-step pipeline executed strictly on a read-only copy.
PostgreSQL DUL(PDU)将底层恢复拆解为五步标准工序,全部动作在独立只读副本上完成:保全文件并配置路径、初始化系统目录、选定目标表、扫描 WAL 候选集、导出 CSV 并做明细记录。
Original section · 对应中文原文
Take a consistent snapshot or clean offline copy covering all real tablespaces, numbered relation segments, TOAST files, and both live and archived WAL. Do not trigger manual checkpoints on the source cluster; point PGDATA and ARCHIVE_DEST in pdu.ini strictly to the copy.
通过一致性快照或停库冷备,完整复制实际表空间、全部分段文件、TOAST 文件以及归档或本地 pg_wal 目录,避免在原库强行执行检查点。在工作副本的 pdu.ini 中将 PGDATA 与 ARCHIVE_DEST 指向副本路径,导出文件写入独立存储。
PostgreSQL: file-system-level backupOriginal section · 对应中文原文
2. Bootstrap catalogs from the copy第二步:启动 PDU 并初始化系统目录
Run b; to load system catalogs directly from the copied PGDATA and verify that the target database is listed. When reading from a copied pg_wal directory, run ckwal; as documented before scanning while keeping the original WAL files untouched.
执行 b; 直接读取副本内的系统表,确认目标数据库已完整列出。若 ARCHIVE_DEST 指向拷贝出的 pg_wal 目录,在扫描前按当前版本要求执行 ckwal; 完成日志校验整理,原始日志文件始终保留不动。
Original section · 对应中文原文
3. Select the exact database, schema, and table第三步:定位目标数据库、模式与表结构
Switch into mydb and public, then inspect t_payment_records with \d+. Verifying schema and column definitions up front prevents extracting from a same-named table in another schema.
切入 mydb 与 public 后执行 \d+ t_payment_records;,提前确认列顺序与数据类型,防止同库不同模式下存在同名表造成导出混淆。
use mydb;
set public;
\d+ t_payment_records;
Original section · 对应中文原文
4. Scan WAL to identify deleted records第四步:扫描 WAL 统计误删候选记录
Execute scan t_payment_records; on the copy to enumerate candidate deletions along with LSN bounds, timestamps, and recommended WAL boundaries. In the documented walkthrough, PDU scanned 9,648 deleted records before export.
在副本上运行 scan t_payment_records;,系统扫出 9,648 条删除候选记录,并输出对应的时间区间、LSN 范围、数据文件 OID 与建议起止 WAL 文件,便于在导出前明确操作范围。
Original section · 对应中文原文
5. Export CSV, report missing FPI rows transparently, and validate第五步:导出 CSV、缺 FPI 透明挂账与隔离库验证
Out of 9,648 scanned candidates in the walkthrough, PDU reconstructed 9,646 rows cleanly and explicitly reported 2 rows that failed due to missing full-page images (Missing FPI blk 272 and blk 253). Load the CSV into an isolated staging table to verify primary keys, TOAST values, and business totals before merging back.
执行全量恢复后,9,648 条候选中成功还原 9,646 条,另外 2 条因缺少可用全页映像(日志明确提示 blk 272 与 blk 253 缺失 FPI)做透明挂账处理,既不静默跳过也不以空值替代。导出的 CSV 先灌入隔离暂存表,完成主键、TOAST 长字段与账务汇总校验后再合入生产。
9,648 scanned candidates = 9,646 reconstructed rows + 2 transparently flagged FPI gaps.
明细统计保持透明挂账:成功条数与缺失 FPI 块号逐一列明,若现场存在更早的 WAL 段,可调前 startwal 重新扫描补齐。
Original section · 对应中文原文
Precision filtering: isolate legitimate deletes精准筛选:按事务号与时间区间剥离正常清理
When a scheduled purge and a mistaken DELETE overlap in the same time window, exporting everything reintroduces deleted junk. Filter by exact transaction IDs and tight WAL intervals so only the target operation is extracted.
当计划内清理任务与误删操作处于同一时段时,全量导出会把本应清理的旧数据一并带回。通过事务模式与时间范围组合筛选,可以只提取误删事务对应的记录。
Original section · 对应中文原文
Target a single transaction ID事务模式按事务号定点导出
Switch to transaction mode (p resmode tx;) and re-scan. In the documented run, running restore del 1360536375; extracted all 50 rows with 0 failures (Success: 50, Failure: 0) into a dedicated CSV without mixing in other transactions.
切换至事务模式(p resmode tx;)重新扫描后,PDU 按事务分组展示删除量。原文针对事务号 1360536375 执行 restore del 1360536375;,精准导出该事务删除的 50 条记录,失败数为 0,避免与其他事务数据混杂。
Original section · 对应中文原文
Narrow the scan window while keeping earlier WAL收紧扫描范围并保留更早的 WAL 段
Record exact WAL segment names and time zone before narrowing the scan via startwal/endwal or starttime/endtime. Keep preceding WAL segments on the copy—reconstructing a deleted row frequently depends on an earlier full-page image.
当目录内 WAL 文件超过 250 个时,可通过 startwal、endwal 或 starttime、endtime 收紧扫描区间以提升效率,但副本中仍须保留更早的 WAL 段,因为还原部分列值要依赖前序检查点周期内的全页映像。
Original section · 对应中文原文
Audit active PDU parameters导出前检查当前生效参数
Run show; or param; before exporting and archive the settings alongside your output: recovery mode, DELETE/UPDATE type, WAL bounds, and timestamps, preventing stale filters from affecting subsequent runs.
执行导出前运行 show; 或 param; 查看 resmode、restype、起止 WAL 段与起止时间并留存记录,防止上一轮筛选条件带入当前导出任务。
Original section · 对应中文原文
Handoff checklist and engineering support标准化交接与应急支持
Archive the source copy ID, tool version, scan window, output checksums, and any flagged keys together. If a live production incident involves missing archives, corrupted catalogs, or unlinked files, keep the source storage read-only and call +86 152 5185 3831 or visit DUL contact page for read-only copy assessment.
完整交接材料应一并记录副本编号、工具版本、扫描窗口、输出文件校验值与异常主键清单。如遇缺归档、系统目录损坏或需整盘碎片扫描等复杂生产故障,请保持原盘只读并与技术支持团队对接,在工作副本上优先验证核心表后再推进全量交付。
Original section · 对应中文原文
Source code and complete command logs开源代码仓库与完整指令日志
Inspect the full walkthrough for complete terminal output and the GitHub repository for build notes. DUL engineers also deploy commercial PDU capabilities on read-only copies when incidents involve damaged catalogs or disk-level fragment reconstruction.
完整终端输出请查阅博客原文,源码与编译说明见 GitHub 开源仓库。面向目录损坏或整盘碎片重组等大型事故,DUL 团队使用商业版 PDU 在只读副本上开展评估与恢复。
PDU project on GitHubOriginal section · 对应中文原文