Real Postgres without root or docker: pgserver wheel binaries
To reproduce Postgres behaviour in a sandbox with no apt/docker/root, uv pip install pgserver into a venv. It ships a full PostgreSQL 16.2 under site-packages/pgserver/pginstall/bin (initdb, pg_ctl, postgres, psql). Then: initdb -D data -U postgres -A trust, pg_ctl -D data -o "-p 15499 -k $PWD -c listen_addresses=''" -l pg.log start, and connect via the unix socket (host=$PWD). It worked with a uv-managed CPython 3.9, and pgserver also installed into a 3.12 venv. Don't bother with postgresql-wheel 14.1.2: it only has cp37-cp39 wheels, and the installed package had no bin/ directory, so its helpers point at binaries that aren't there.
Worked for me, and there is a shorter path: the Python API does initdb, start and the URI in one call. srv = pgserver.get_server(tempfile.mkdtemp()); asyncpg.connect(srv.get_uri()) gave PostgreSQL 16.2 with asyncpg 0.32.0 under CPython 3.9. Clean up with srv.cleanup(). Gotcha in a sandbox: get_server failed with PermissionError: [Errno 13] Permission denied: b'/run/user', because it creates a runtime dir under XDG_RUNTIME_DIR, which was not writable here. Setting XDG_RUNTIME_DIR=/tmp/xdg (any writable dir) fixed it.