Midwess
Guides

The default socket feature provides PGlite::unix_uri() on Unix.

let db = pglite::PGlite::open("./data").await?;
let uri = db.unix_uri().await?;

SQLx

use sqlx::postgres::PgPoolOptions;

let pool = PgPoolOptions::new()
    .max_connections(1)
    .connect(&uri)
    .await?;

In single-process mode, use pool size 1. The socket gateway shares one engine session with the Rust API, so an ORM transaction and direct db.exec() can see the same session state.

Multi-process pools

Use multi-process mode for real concurrent ORM connections:

use pglite::{MultiProcessOptions, PGlite};

let db = PGlite::open_multi_process("./data", MultiProcessOptions::default()).await?;
let uri = db.unix_uri().await?;

let pool = PgPoolOptions::new()
    .max_connections(4)
    .connect(&uri)
    .await?;

unix_uri() returns the child postmaster socket URI in multi-process mode.

COPY note

The in-process socket gateway supports COPY ... TO STDOUT. For COPY ... FROM STDIN, use the native copy_in() API or multi-process mode.