When authoring end-to-end tests that exercise PostgreSQL while the harness is
still running as root, follow these steps:
- Invoke
pg_embedded_setup_unprivbefore handing control to less-privileged workers. This prepares file ownership, caches the binaries, and records the superuser password in a location accessible tonobody. - Export the
PG_EMBEDDED_WORKERenvironment variable with the absolute path to thepg_workerhelper binary. The library invokes this helper when it needs to execute PostgreSQL lifecycle commands asnobody. - Keep the test process running as
root; the helper binary demotes itself before calling intopostgresql_embeddedso the main process never changes UID mid-test. - Ensure the
PGPASSFILEenvironment variable points to the file created in the runtime directory so subsequent Diesel or libpq connections can authenticate without interactive prompts. Thebootstrap_for_tests().environment.pgpass_filehelper 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 setsTZautomatically and, on Unix-like hosts, also seedsTZDIRwhen it discovers a valid timezone database.