Testing with `pg_embedded_setup_unpriv`

Version 0.3.0 Updated Jul 22, 2026

The PostgreSQL integration tests use pg_embedded_setup_unpriv to run embedded PostgreSQL without requiring a system PostgreSQL service. A test process starts one shared embedded cluster handle, and each PostgreSQL test receives its own temporary database cloned from a template. This keeps database state isolated without paying the cost of starting a new server for every test.

Use make test for the normal workflow. The Makefile runs prepare-pg-worker, builds the locked pg_worker helper, exports PG_EMBEDDED_WORKER, and creates a unique writable runtime base under target/pg-embed-runs/<run-id>. PG_RUNTIME_DIR and PG_DATA_DIR live under that base, which is created with the sticky bit set, so the helper can use it safely.

When bypassing make test, unprivileged cargo test runs may use the upstream defaults. Root-capable runs must prepare pg_worker first and export PG_EMBEDDED_WORKER themselves; run make prepare-pg-worker, then set PG_EMBEDDED_WORKER=target/pg_worker.

The suite deliberately does not use an external PostgreSQL test URL. Embedded PostgreSQL keeps local, Continuous Integration, and sandboxed agent runs on the same lifecycle and authentication path, which makes failures easier to reproduce across environments.