Integrating with root-only test agents

Version 0.1.0 Updated Nov 08, 2025

When authoring end-to-end tests that exercise PostgreSQL while the harness is still running as root, follow these steps:

  • Invoke pg_embedded_setup_unpriv before handing control to less-privileged workers. This prepares file ownership, caches the binaries, and records the superuser password in a location accessible to nobody.
  • Export the PG_EMBEDDED_WORKER environment variable with the absolute path to the pg_worker helper binary. The library invokes this helper when it needs to execute PostgreSQL lifecycle commands as nobody.
  • Keep the test process running as root; the helper binary demotes itself before calling into postgresql_embedded so the main process never changes UID mid-test.
  • Ensure the PGPASSFILE environment variable points to the file created in the runtime directory so subsequent Diesel or libpq connections can authenticate without interactive prompts. The bootstrap_for_tests().environment.pgpass_file helper returns the path if the bootstrap ran inside the test process.
  • Provide TZDIR=/usr/share/zoneinfo (or the correct path for your distribution) if you are running the CLI. The library helper sets TZ automatically and, on Unix-like hosts, also seeds TZDIR when it discovers a valid timezone database.