pg_dbmigrator
A Rust library for migrating PostgreSQL databases between two endpoints.
- Offline — performs
pg_dumpagainst the source andpg_restore(orpsql) against the target. Equivalent to a one-shot dump-and-load. - Online — first creates a logical replication slot on the source with
EXPORT_SNAPSHOT, runs a snapshot-consistentpg_dump/pg_restore, and then issuesCREATE SUBSCRIPTIONon the target so PostgreSQL's built-in apply worker streams WAL changes from the slot until the operator triggers cutover.
The crate is split into small, single-purpose modules so that it can be consumed both as a library and from the bundled CLI binary.
High level usage
use pg_dbmigrator::{MigrationConfig, MigrationMode, Migrator, EndpointConfig};
use tokio_util::sync::CancellationToken;
# async fn run() -> pg_dbmigrator::Result<()> {
let cfg = MigrationConfig {
mode: MigrationMode::Offline,
source: EndpointConfig::parse("postgresql://user:pw@src/db")?,
target: EndpointConfig::parse("postgresql://user:pw@dst/db")?,
..MigrationConfig::default()
};
let migrator = Migrator::new(cfg);
migrator.run(CancellationToken::new()).await?;
# Ok(())
# }
See the examples/ directory for full programs.