theseus-rs/postgresql-embedded

Embed PostgreSQL database

Rust

397

662 commits

updated Aug 30, 2026

See the code

README

PostgreSQL Embedded

ci Documentation Code Coverage Latest version License Semantic Versioning

Install and run a PostgreSQL database locally on Linux, MacOS or Windows. PostgreSQL can be bundled with your application, or downloaded on demand.

This library provides an embedded-like experience for PostgreSQL similar to what you would have with SQLite. This is accomplished by downloading and installing PostgreSQL during runtime. There is also a "bundled" feature that when enabled, will download the PostgreSQL installation archive at compile time, include it in your binary and install from the binary version at runtime. In either case, PostgreSQL will run in a separate process space.

Features

  • installing and running PostgreSQL
  • running PostgreSQL on ephemeral ports
  • Unix socket support
  • async and blocking API
  • bundling the PostgreSQL archive in an executable
  • semantic version resolution
  • ability to configure PostgreSQL startup options
  • settings builder for fluent configuration
  • URL based configuration
  • choice of native-tls or rustls with AWS-LC or Ring
  • support for installing PostgreSQL extensions

Getting Started

Example

use postgresql_embedded::{PostgreSQL, Result};

#[tokio::main]
async fn main() -> Result<()> {
    let mut postgresql = PostgreSQL::default();
    postgresql.setup().await?;
    postgresql.start().await?;

    let database_name = "test";
    postgresql.create_database(database_name).await?;
    postgresql.database_exists(database_name).await?;
    postgresql.drop_database(database_name).await?;

    postgresql.stop().await
}

Notes

Supports using PostgreSQL binaries from:

Safety

These crates use #![forbid(unsafe_code)] to ensure everything is implemented in 100% safe Rust.

License

Licensed under either of

at your option.

PostgreSQL is covered under The PostgreSQL License.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Prior Art

Projects that inspired this one:

bundle
database
embedded
install
installer
postgres
postgresql

Contributors

brianheineman

625 commits

gazure

5 commits

ctron

3 commits

theseus-rs/postgresql-embedded

Embed PostgreSQL database

Rust

397

662 commits

updated Aug 30, 2026

See the code

README

PostgreSQL Embedded

ci Documentation Code Coverage Latest version License Semantic Versioning

Install and run a PostgreSQL database locally on Linux, MacOS or Windows. PostgreSQL can be bundled with your application, or downloaded on demand.

This library provides an embedded-like experience for PostgreSQL similar to what you would have with SQLite. This is accomplished by downloading and installing PostgreSQL during runtime. There is also a "bundled" feature that when enabled, will download the PostgreSQL installation archive at compile time, include it in your binary and install from the binary version at runtime. In either case, PostgreSQL will run in a separate process space.

Features

  • installing and running PostgreSQL
  • running PostgreSQL on ephemeral ports
  • Unix socket support
  • async and blocking API
  • bundling the PostgreSQL archive in an executable
  • semantic version resolution
  • ability to configure PostgreSQL startup options
  • settings builder for fluent configuration
  • URL based configuration
  • choice of native-tls or rustls with AWS-LC or Ring
  • support for installing PostgreSQL extensions

Getting Started

Example

use postgresql_embedded::{PostgreSQL, Result};

#[tokio::main]
async fn main() -> Result<()> {
    let mut postgresql = PostgreSQL::default();
    postgresql.setup().await?;
    postgresql.start().await?;

    let database_name = "test";
    postgresql.create_database(database_name).await?;
    postgresql.database_exists(database_name).await?;
    postgresql.drop_database(database_name).await?;

    postgresql.stop().await
}

Notes

Supports using PostgreSQL binaries from:

Safety

These crates use #![forbid(unsafe_code)] to ensure everything is implemented in 100% safe Rust.

License

Licensed under either of

at your option.

PostgreSQL is covered under The PostgreSQL License.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Prior Art

Projects that inspired this one:

bundle
database
embedded
install
installer
postgres
postgresql

Contributors

brianheineman

625 commits

gazure

5 commits

ctron

3 commits

Languages

Rust

100.0%