libpgdump
A Rust library for reading and writing PostgreSQL dump files.
Supports all three pg_dump formats: custom (-Fc), directory (-Fd),
and tar (-Ft).
Usage
Add to your Cargo.toml:
[]
= "1"
Load an existing dump
use libpgdump;
let dump = load.unwrap;
println!;
println!;
println!;
// Iterate over table data
for row in dump.table_data.unwrap
// Look up a specific entry
if let Some = dump.lookup_entry
Create a new dump
use libpgdump;
let mut dump = new.unwrap;
// Add a table definition
let table_id = dump.add_entry.unwrap;
// Add table data
let data_id = dump.add_entry.unwrap;
dump.set_entry_data.unwrap;
// Save with gzip compression
dump.set_compression;
dump.save.unwrap;
Inspect entries
use libpgdump;
let dump = load.unwrap;
for entry in dump.entries
Error handling
use ;
match load
Supported features
- Read/write custom (
-Fc), directory (-Fd), and tar (-Ft) archives - Compression: none, gzip, lz4, and zstd
- Archive versions 1.12.0 through 1.16.0 (PostgreSQL 9.0–18)
- Version-aware parsing: handles all format variations across versions
- 60+ object types: tables, indexes, views, functions, constraints, extensions, etc.
- Large object (blob) support
- Weighted topological sort: entries are sorted on save matching pg_dump's dependency-aware ordering
- Programmatic dump creation: build dumps from scratch with the builder API
Format details
Dump::load() auto-detects the format from file type (directory) or magic bytes (PGDMP = custom, ustar = tar).
Custom format (-Fc)
Binary archive: header with magic bytes, version, and compression info; metadata (timestamp, database name, versions); TOC with entry definitions and dependencies; compressed or uncompressed data blocks.
Directory format (-Fd)
A directory containing toc.dat (binary TOC in custom format) and per-entry .dat data files. Supports all compression algorithms.
Tar format (-Ft)
A standard tar archive containing toc.dat and per-entry data files. Does not support compression.
Minimum Rust version
Rust 1.88 or later (edition 2024).
License
BSD-3-Clause