A Go package shim for running PostgreSQL database dumps using pg_dump and pg_dumpall.
- Run
pg_dumpfor single database dumps - Run
pg_dumpallfor full cluster dumps - Stream dump output directly to your application
- Automatic process cleanup
go get github.com/taigrr/go-pgdumpimport "github.com/taigrr/go-pgdump"
opts := pgdump.Opts{
Host: "localhost",
Port: "5432",
User: "postgres",
Password: "secret",
}
reader, err := pgdump.DumpDB(ctx, "mydb", opts)
if err != nil {
log.Fatal(err)
}
defer reader.Close()
// Read the dump output
dump, err := io.ReadAll(reader)
if err != nil {
log.Fatal(err)
}reader, err := pgdump.DumpAll(ctx, "", opts)
if err != nil {
log.Fatal(err)
}
defer reader.Close()- Go 1.24.2+
- Docker (for running tests)
- PostgreSQL client tools (
pg_dump,pg_dumpall)
go test -vTests use testcontainers to spin up a PostgreSQL instance and execute both single database and full cluster dumps.
0BSD