百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

pg-embed

> 编程语言
开源

在 Linux、MacOS 或 Windows 上本地运行 PostgreSQL 数据库,作为其他 Rust 应用程序或测试的一部分。

176 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

在 Linux、MacOS 或 Windows 上本地运行 PostgreSQL 数据库,作为其他 Rust 应用程序或测试的一部分。

pg-embed

Run a PostgreSQL server locally as part of a Rust application or test suite — no system installation required.


pg-embed downloads precompiled PostgreSQL binaries from zonkyio/embedded-postgres-binaries, caches them on first use, and manages the full server lifecycle (initdb → pg_ctl start → pg_ctl stop). Built on tokio.

Contents

  • Quick start
  • Extensions
  • Features
  • Platform support
  • Binary cache
  • Documentation

Quick start

toml
[dependencies]
pg-embed = "1.0"
…

Extensions

Third-party extensions (pgvector, PostGIS, etc.) are not included in the precompiled binaries. To install one, point install_extension() at a directory containing the pre-built files for your platform. Call it after setup() and before start_db().

use std::path::Path;

// After pg.setup() and before pg.start_db():
pg.install_extension(Path::new("extensions/pgvector")).await?;
pg.start_db().await?;

// Then activate it inside a database:
// CREATE EXTENSION IF NOT EXISTS vector;

Files are routed by extension:

File type Destination
.so, .dylib, .dll {cache}/lib/
.control, .sql {cache}/share/postgresql/extension/
Anything else Skipped

Pure-SQL extensions (no shared library) work the same way — simply omit the binary.


Features

Capability API Feature flag
Server lifecycle setup(), start_db(), stop_db() rt_tokio
Extension installation install_extension() rt_tokio
️ Database management create_database(), drop_database(), database_exists() rt_tokio_migrate
Migrations migrate() rt_tokio_migrate

The default feature is rt_tokio_migrate (includes sqlx). For a smaller build without sqlx:

toml
pg-embed = { version = "1.0", default-features = false, features = ["rt_tokio"] }

Additional behaviours included in all builds:

  • Binary caching — binaries are downloaded once per OS/arch/version and reused across runs.
  • Automatic shutdown — pg_ctl stop is called on drop if the server is still running.
  • Concurrent safety — a global lock prevents duplicate downloads when multiple instances initialise simultaneously.

Platform support

OS Architectures
amd64, arm64v8 ¹
amd64, i386, arm32v6, arm32v7, arm64v8, ppc64le
amd64, i386, arm32v6, arm32v7, arm64v8, ppc64le
amd64, i386

Supported PostgreSQL versions: 10 – 18 (PG_V10 … PG_V18 constants).

¹ Apple Silicon binaries are available for PostgreSQL 14 and later only.


Binary cache

Binaries are stored at an OS-specific location and reused on subsequent runs:

OS Cache path
macOS ~/Library/Caches/pg-embed/
Linux $XDG_CACHE_HOME/pg-embed/ or ~/.cache/pg-embed/
Windows %LOCALAPPDATA%\pg-embed\

Documentation

  • User Handbook — configuration reference, auth methods, migrations, FAQ
  • Technical Handbook — architecture, data flow, module graph, internals
  • API reference on docs.rs

License

pg-embed is dual-licensed under MIT / Apache 2.0.


Credits

Precompiled binaries provided by zonkyio/embedded-postgres-binaries, hosted on Maven Central.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rust

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言