libpgdump
A Rust library for reading and writing PostgreSQL dump files.
Currently supports the custom format (pg_dump -Fc), with planned
support for tar and directory formats.
Usage
Add to your Cargo.toml:
[]
= "0.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 format (
-Fc) 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
- Programmatic dump creation: build dumps from scratch with the builder API
Archive format reference
The custom format is a binary archive containing:
| Component | Description |
|---|---|
| Header | Magic bytes (PGDMP), version, sizes, format, compression |
| Metadata | Timestamp, database name, server version, pg_dump version |
| TOC | Table of contents with entry definitions and dependencies |
| Data blocks | Compressed or uncompressed table data and large objects |
Minimum Rust version
Rust 1.88 or later (edition 2024).
License
BSD-3-Clause