Skip to content

pgx run — one command to a ready database (stacked on #2) - #4

Merged
alexshapalov merged 7 commits into
mainfrom
feat/pgx-run
Oct 18, 2026
Merged

alexshapalov merged 7 commits into
mainfrom
feat/pgx-run

Conversation

@alexshapalov

Copy link
Copy Markdown
Contributor

pgx run — one command to a ready database

Stacked on #2. The developer onboarding the public install promises:

curl -fsSL https://pgx.dev/install | sh
pgx run

pgx run initialises $PGX_HOME if needed, starts the runtime if it is not already up, ensures a default app database, and prints its connection URL. Every step is idempotent and safe to repeat; it never resets or overwrites an existing database.

$ pgx run
PGX is ready.

  postgres://postgres:…@127.0.0.1:5432/app

  database   app (created)
  runtime    started (pid 23469, port 5432)
  home       /home/you/.pgx

Connect:
  psql "postgres://postgres:…@127.0.0.1:5432/app"

Behaviour

  • Idempotent: a second pgx run reports app (existing) / runtime already running and does not restart or duplicate anything.
  • A run-level flock serialises concurrent invocations, so even a first run from several processes at once cannot race in init; one engine starts, one app is created.
  • --json emits a single object (ready, url, database, database_created, started, already_running, pid, port, …) for agents.
  • Secure localhost-only defaults inherited from init: loopback listen_addresses, scram-sha-256 over TCP, a random password. The first run honours PGX_PORT / PGX_DURABILITY / PGX_PASSWORD.
  • Engine untouched: the change is entirely within crates/bin/pgx; start/restart behaviour is unchanged (existing lifecycle tests stay green).

Tests (all green locally against the assembled distribution)

  • tests/run.rs (8): fresh install → ready; idempotent, no duplicates; persistence across restart; existing databases untouched; localhost-only + password-protected; 8-way concurrent runs (one engine, one app); recovery after an engine crash.
  • Full crate suite 104 tests; Python SQL regression 19; five app fixtures (psql/node/python/go/rails) PASS; installer end-to-end PASS.

Also contains a CI fix (inherited from #2): the Unit tests step is scoped to --bin pgx so it no longer pulls in the dist-dependent integration suites, and the run suite is added to the black-box step.

🤖 Generated with Claude Code

alexshapalov and others added 6 commits October 17, 2026 21:39
pgx run initialises $PGX_HOME if needed, starts the runtime if it is not
already up, ensures a default `app` database, and prints its connection URL.
Every step is idempotent and safe to repeat; it never resets or overwrites an
existing database. A run-level flock serialises concurrent invocations so a
fresh first run cannot race in init, and --json emits a single object for
agents. Secure localhost-only defaults are inherited from init (loopback,
scram-sha-256, random password).

Refactors start into a non-emitting ensure_running returning a StartOutcome so
run reports the whole operation once; adds Out::quiet() for composite commands.
start/restart behaviour is unchanged (existing lifecycle tests stay green).

Tests (tests/run.rs, against the assembled distribution): fresh install,
idempotency with no duplicates, persistence across restart, existing databases
untouched, localhost-only + password-protected defaults, 8-way concurrent runs
(one engine, one app), and recovery after an engine crash.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add --test run to the black-box CI step so tests/run.rs runs on every PR.
Document `pgx run` as the one-command quick start in the CLI reference and
the install guide (curl … | sh, then pgx run).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The container ran as root, and the PGX engine (like PostgreSQL) refuses
"root execution of the PostgreSQL server" — so `pgx serve` exited status 1 and
the container never accepted TCP. Add an unprivileged `pgx` user, own the
data/run dirs, COPY the distribution --chown=pgx (so the bundled base cluster,
mode 700, is readable), and USER pgx. The named volume inherits pgx ownership.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The ETXTBSY retry was only on run(); run_cmd/spawn_run (used by the pgx run
suite) still panicked on a transient 'Text file busy' exec of the freshly
copied binary under CI parallelism. Route all three spawn paths through one
output_retrying helper (and retry spawn_run's spawn).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@alexshapalov
alexshapalov changed the base branch from pgx-release-strategy to main October 18, 2026 06:32
@alexshapalov
alexshapalov merged commit 8787480 into main Oct 18, 2026
3 checks passed
@alexshapalov
alexshapalov deleted the feat/pgx-run branch October 18, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant