百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

PDU-PostgreSQLDataUnloader

> 数据库
开源

用于修复损坏或离线的 PGDATA、基于 WAL 的行恢复和丢失表的恢复的开源 PostgreSQL 数据恢复工具。

100 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

用于修复损坏或离线的 PGDATA、基于 WAL 的行恢复和丢失表的恢复的开源 PostgreSQL 数据恢复工具。


What is PDU?

PDU (PostgreSQL Data Unloader) is a professional-grade, open-source disaster recovery and data extraction tool for PostgreSQL databases (versions 14-18). It reads PostgreSQL data files directly without requiring a running database instance—making it the ultimate solution for disaster recovery, forensic analysis, and emergency data extraction.

The Problem

PostgreSQL DBAs face critical scenarios like these:

▸ Database completely corrupted - won't start, can't recover ▸ Accidental DELETE/UPDATE - critical data gone in seconds ▸ Data files deleted - filesystem corruption or operator error

Traditional tools like pg_filedump, pg_dirtyread, and pg_waldump each solve one problem with different learning curves. PDU unifies all these scenarios into a single, intuitive tool.

In Oracle ecosystems, professionals use ODU/DUL for direct data mining. PostgreSQL deserved the same level of capability—that's why PDU exists.


✨ Why Choose PDU?

✓ Simple & Unified

Two files (pdu + pdu.ini), zero dependencies. One tool handles corruption, deletion, and updates.

✓ Safe & Instant

100% read-only operations. Your original data files remain untouched. Recover data faster than traditional PITR methods.

✓ Unique & Compatible

Powerful direct data file reading capabilities. Supports PostgreSQL 14-18.


Core Capabilities

PDU handles three critical disaster scenarios with two recovery methods:

Three Disaster Scenarios

Scenario What Happened PDU Solution Guide
▸ Database Corruption PostgreSQL won't start due to catalog/file corruption Extract data directly from damaged files Read →
▸ Accidental DELETE/UPDATE Wrong DELETE/UPDATE executed in production Replay WAL archives to recover original data Read →
▸ Data File Loss Specific data files deleted or corrupted Rebuild data from remaining files Read →

️ Two Recovery Methods

1. Direct Data File Extraction

  • Parse PostgreSQL heap/TOAST files directly
  • Bypass database engine entirely
  • fast parsing of TOAST data

2. WAL Archive Scanning

  • Analyze Write-Ahead Logs (WAL) for transaction history
  • Extract deleted rows or pre-update values
  • Time-based and transaction-based filtering

Quick Start

Step 1: Build PDU

bash
# Set PostgreSQL version (14-18)
sed -i 's/#define PG_VERSION_NUM [0-9]\+/#define PG_VERSION_NUM /g' basic.h

# Compile
make

# Result: ./pdu executable

Step 2: Configure pdu.ini

ini
PGDATA=/var/lib/postgresql/15/main
ARCHIVE_DEST=/var/lib/postgresql/wal_archive

Step 3: Launch PDU

bash
./pdu

Step 4: Interactive Commands

sql
PDU> b;                    -- Bootstrap metadata from PGDATA
PDU> \l;                   -- List databases
PDU> use production_db;    -- Switch database
PDU> \dn;                  -- List schemas
PDU> set public;           -- Switch schema
PDU> \dt;                  -- List tables
PDU> \d+ customers;        -- Describe table structure
PDU> unload tab customers; -- Export one table to CSV

Full Guide: pduzc.com/quickstart


Usage Examples

Scenario 1: Extract Data from Corrupted Database

Problem: PostgreSQL won't start due to corrupted system catalog.

Solution:

sql
PDU> b;                          -- Initialize metadata
PDU> use mydb;
PDU> set public;
PDU> unload tab customers;       -- Export one table
PDU> unload sch public;          -- Export all tables in schema
PDU> unload ddl;                 -- Generate DDL for current schema
PDU> unload copy;                -- Generate COPY script for exported CSVs

Result: CSV files exported to current directory, even if PostgreSQL won't start.


Scenario 2: Recover Deleted Records

Problem: A critical DELETE statement was executed, and you need the deleted rows back.

Solution:

sql
PDU> use production;
PDU> set public;
PDU> param restype delete;       -- Scan DELETE records
PDU> param resmode tx;           -- Restore by transaction ID
PDU> scan orders;                -- Scan WAL for deleted rows
PDU> restore del ;         -- Restore one transaction from scan results

Result: Deleted rows recovered from WAL archives and exported to CSV.

For time-range recovery, use param resmode time;, set param starttime ; and param endtime ;, then run scan orders; and restore del all;.


Scenario 3: Undo Accidental UPDATE

Problem: An UPDATE statement modified hundreds of rows with wrong values.

Solution:

sql
PDU> use production;
PDU> set public;
PDU> param restype update;       -- Scan UPDATE records
PDU> param resmode tx;           -- Restore by transaction ID
PDU> scan users;
PDU> restore upd ;         -- Restore pre-UPDATE values

Result: Original values before UPDATE statement recovered from WAL.

More Scenarios: pduzc.com/docs/instant-recovery


Command Reference

Command Description
b; Bootstrap metadata from PGDATA
use ; Switch to specified database
set ; Switch to specified schema
\l; List all databases
\dn; List schemas in current database
\dt; List tables in current schema
\d+ ; Describe table structure (columns, types)
\d ; Show table column types
u tab ; / unload tab ; Export one table to CSV
u sch ; / unload sch ; Export all tables in a schema
u ddl; / unload ddl; Generate DDL for the current schema
u copy; / unload copy; Generate COPY statements for exported CSVs
scan ; Scan WAL archives for DELETE/UPDATE records of one table
scan manual; Initialize metadata from files under the manual directory
scan drop; Scan WAL for dropped/truncated table metadata
meta tab ; Write one table's metadata to tab.config
meta sch ; Write all table metadata for a schema to tab.config
restore del ; Restore deleted rows for one scanned transaction
restore upd ; Restore pre-UPDATE rows for one scanned transaction
restore del all; / restore upd all; Restore scanned results in time-range mode
add ; Manually add table metadata; put data files in restore/datafile
restore db ; Initialize a custom database directory (Pro/Enterprise)
dropscan idx; / ds idx; Build dropped-page index (Pro/Enterprise)
dropscan; / ds; Scan disk using tables in tab.config (Pro/Enterprise)
dropscan iso; / ds iso; Recover from an image file using tables in tab.config (Pro/Enterprise)
dropscan repair; / ds repair; Retry failed TOAST table scans (Pro/Enterprise)
dropscan clean; / ds clean; Clean restore/dropscan directories (Pro/Enterprise)
dropscan copy; / ds copy; Generate COPY commands for DropScan output (Pro/Enterprise)
p startwal ; / param startwal ; Set WAL scan start file
p endwal ; / param endwal ; Set WAL scan end file
p starttime ; / param starttime ; Set time-range recovery start time
p endtime ; / param endtime ; Set time-range recovery end time
p resmode tx|time; / param resmode tx|time; Set recovery mode
p restype delete|update; / param restype delete|update; Set recovery type
p exmode csv|sql; / param exmode csv|sql; Set export format
p encoding utf8|gbk; / param encoding utf8|gbk; Set output encoding
p isomode on|off; / param isomode on|off; Set image-save mode
reset ; / reset all; Reset one parameter or all parameters
show; Display current parameters
t; Display supported data types
exit; / \q; Exit PDU

All interactive commands must end with ;.

Full Reference: pduzc.com/docs


⚙️ Configuration (pdu.ini)

Parameter Description Example
PGDATA PostgreSQL data directory path /var/lib/postgresql/15/main
ARCHIVE_DEST WAL archive directory (for DELETE/UPDATE recovery) /var/lib/postgresql/wal_archive

Supported Data Types

✅ Fully Supported

  • Numeric: int2, int4, int8, float4, float8, numeric, decimal
  • Temporal: date, time, timestamp, timestamptz, interval
  • Text: varchar, text, char, bpchar
  • JSON: json
  • UUID: uuid
  • Network: inet, cidr, macaddr, macaddr8
  • TOAST: Automatically handles large objects with LZ4 decompression

❌ Not Supported

  • User-defined enum types
  • Composite types
  • Range types (int4range, tsrange, etc.)
  • Full-text search vectors (tsvector, tsquery)

Recovery Workflows

Comprehensive guides available at pduzc.com/docs/instant-recovery

Scenario Description Official Guide
Corrupted Instance PostgreSQL won't start—extract data straight from disk Open Guide →
Corrupted Datafile Specific datafile damaged—salvage reachable data Open Guide →
Corrupted Database Entire database broken—reconstruct catalog and data Open Guide →
Deleted Records Rows accidentally deleted—replay WAL to recover Open Guide →
Updated Records Wrong UPDATE executed—rollback with WAL analysis Open Guide →
No Backup: DELETE / DROP TABLE / DROP DATABASE Compare PITR, pg_dirtyread, pg_filedump, PDU, and professional recovery Decision Guide →

❓ FAQ / Troubleshooting

Compilation Issues

Q: make fails with "lz4.h: No such file or directory"

A: Install LZ4 development library:

bash
# Ubuntu/Debian
sudo apt-get install liblz4-dev zlib1g-dev

# RHEL/CentOS
sudo yum install lz4-devel zlib-devel

Q: How do I change the PostgreSQL version target?

A: Edit basic.h and modify PG_VERSION_NUM:

bash
sed -i 's/#define PG_VERSION_NUM [0-9]\+/#define PG_VERSION_NUM 16/g' basic.h
make clean && make

Configuration Issues

Q: PDU shows "PGDATA directory not found"

A: Verify the PGDATA path in pdu.ini is correct and accessible:

bash
ls -la /var/lib/postgresql/15/main

Usage Issues

Q: WAL scanning (scan ) returns no results

A: Ensure:

  • ARCHIVE_DEST in pdu.ini points to the correct WAL archive directory
  • WAL archiving was enabled when the DELETE/UPDATE occurred
  • Make sure WAL files scanned includes the DELETE/UPDATE operations

Q: Exported CSV files contain garbled characters

A: Check database encoding:

sql
PDU> \l;  -- Look at the encoding column

The CSV will use the database's encoding. Convert if needed:

bash
iconv -f UTF8 -t GBK input.csv > output.csv

Performance Optimization

Q: Unloading large tables takes too long

A: PDU performs full table scans. For better performance:

  • Run PDU on a machine with fast disk I/O
  • Consider unloading specific columns only (if supported in future versions)
  • Use parallel exports for different tables

System Requirements

  • OS: Linux (x86_64)
  • Compiler: GCC (C99 standard)
  • Libraries:
    • liblz4-dev (Debian/Ubuntu) or lz4-devel (RHEL/CentOS

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Cdata-rescuedatabase-forensicsdatabase-recoverydisaster-recovery

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库