This is PDU's most powerful feature. When tables are dropped or truncated, PostgreSQL marks the space as free but doesn't immediately overwrite the data. PDU can find and recover this data through disk fragment scanning.
The only publicly documented practical method to restore DROP TABLE or TRUNCATE without backups.
Critical Factors for Success
Time is critical
Recovery success depends on whether disk space has been overwritten. The sooner you attempt recovery, the higher the success rate.
Stop database writes if possible
Minimize the chance of data page overwrite by reducing database activity.
Table structure helps but is not required
PDU can work even without original table schema information.
vim pdu.ini#PostgreSQL Data DirectoryPGDATA=/home/pg/data/#PostgreSQL Archive DirectoryARCHIVE_DEST=/home/pg/wal_arch#Disk for dropScan to scanDISK_PATH=/dev/mapper/data-lv#Number of data blocks to skip during dropScanBLOCK_INTERVAL=20#PGDATA to be excluded during dropscanPGDATA_EXCLUDE=
The scanned tables are saved in the restore database. Switch to it and use meta tab to export the table structure:
mydb.public=# use restore;┌────────────────────────────────────────┐│ Schema │ Tab Num │├────────────────────────────────────────┤│ public │ 1 │└────────────────────────────────────────┘restore.public=# meta tab gp_business_event;gp_business_event varchar,bpchar,varchar,varchar,varchar,varchar,varchar,date,varchar,varchar,varchar,varchar,varchar,varchar,timestamptz,varchar,timestamptz,bpchar,varcharCompleted, imported 1 dropscan-capable table objects in total
Before scanning, PDU builds an index of PostgreSQL data pages on the disk to minimize recovery time. This step excludes existing table data from the scan.
PDU.public=# ds idx;▌ Starting index retrieval┌─────────────────────────────────────────────────────────────────────────────────────────────────────┐ ● Existing data pages will be excluded during index retrieval└─────────────────────────────────────────────────────────────────────────────────────────────────────┘Excluding file data pages under directory </home/pg/data/>Excluding file data pages under directory </home/pg/data/pg_wal>Excluding file data pages under directory </home/pg/data/base>Excluding file data pages under directory </home/pg/data/base/16384>Excluding file data pages under directory </home/pg/data/global>... (more directories) ...=== Disk Scan Process Monitor ===Thread 0: 98.26% (Offset: 34288435200/34894512128) Pages: 30879Thread 1: 100.00% (Offset: 69789024256/69789024256) Pages: 0Total: 99.13% Pages: 30879 Time Elapsed: 111.2sEstimating Time Left: 1.0 Seconds
Or use scan drop to batch generate, then use meta sch schema_name to add all tables in a schema:
restore.public=# meta sch public;
Completed, imported 5 dropscan-capable table objects in total
Q: What if disk fragments have been overwritten?
PDU supports saving data page fragments as image files during the index scan phase. Enable isomode before running ds idx:
PDU.public=# p isomode on;
PDU.public=# ds idx; -- This saves page images
-- Later, use iso mode for scanning:
PDU.public=# ds iso;
This allows recovery even if original disk fragments are later overwritten.
Q: What does 'Suspected gibberish' mean in the output?
This indicates records that PDU found but suspects may be corrupted or contain invalid data. These records are still included in the output but should be reviewed carefully.
Q: How long does the scanning process take?
Scanning time depends on disk size and the BLOCK_INTERVAL setting. A smaller BLOCK_INTERVAL provides more comprehensive disk coverage but is slower. For faster scanning on large disks, increase the BLOCK_INTERVAL value.
Best Practice
For critical data, enable isomode immediately after discovering the drop/truncate to preserve disk page images. This provides a safety net even if the actual disk pages are overwritten later.