Repository navigation
Description
Several day-2 paths in the native install exit 0 while the system is not in the state they report. Mostly non-systemd hosts. Related: #727, #732.
Items
- documentdb-setup: pg_ctl restart path omits -l, so the new postmaster keeps setup's stdout and hangs piped callers
- documentdb-setup (non-systemd): scoped --restore and --status ignore the recorded gateway PID, so success/health can be false
- Reset and package removal report success while PostgreSQL or the gateway is still running (non-systemd)
- documentdb-setup re-run resets DOCUMENTDB_LISTEN_ADDR to a wildcard bind and never updates documentdb_core
- documentdb-setup configures a major with no documentdb-N package; apt autoremove can then remove a running install
- documentdb-gateway --check reports OK when pg_hba/pg_ident changes haven't been reloaded
1. documentdb-setup: pg_ctl restart path omits -l, so the new postmaster keeps setup's stdout and hangs piped callers
On non-systemd hosts, when PostgreSQL is already running and the config changed (e.g. re-running with --restore, or DOCUMENTDB_TOAST_COMPRESSION changed), documentdb-setup restarts it with:
documentdb-local/scripts/documentdb-setup.sh:3078
run_as_user documentdb-local "${PG_CTL}" -D "${DATA_DIR}" -w restart # no -l
while the start path at :3084 passes -l "${DATA_DIR}/pglog.log". Without -l the new postmaster inherits setup's stdout/stderr. Setup prints SUCCESS: DocumentDB is ready and exits, but the pipe stays open, so any caller reading it (| tee, | cat, $(...), CI log capture) blocks until timeout. A minimal pg_ctl restart | cat without -l times out; with -l it returns.
Side effects: PG log lines leak into the caller's stdout/file instead of pglog.log, which the setup hint at :3804 points users to.
Related: the gateway fallback launch (:3602) uses nohup ... & without setsid, so it stays in the caller's process group. When the hung caller is Ctrl-C'd or hit by a CI timeout SIGTERM, the gateway gets the signal too and the service ends up down after a success message.
Fix: add -l "${DATA_DIR}/pglog.log" to the restart at :3078, and consider setsid for the gateway launch (check the pidfile/exe-match logic still holds). A regression test could run the restart path with stdout piped to cat under a timeout.
2. documentdb-setup (non-systemd): scoped --restore and --status ignore the recorded gateway PID, so success/health can be false
Without systemd, documentdb-setup writes a per-port record at gateway launch (nohup_gateway_pid_for_port) but several paths ignore it. Static read of documentdb-local/scripts/documentdb-setup.sh on main:
- Scoped
--restore --pg-version N(:4852) skips the nohup sweep, deletessetup.conf, then prints "Restore complete" and exits 0 (:4884). The gateway keeps serving and can no longer be located via state. The recorded port isn't read first. --status(:4240) reportsactive (nohup; no systemd)whenever anything listens on the port, with no PID/exe check, and exits 0 if mode is configured. A foreign listener reads as healthy.--listen-portchange (start_gateway, :3433 onward) only inspects the new port; the previously persisted port's gateway keeps running. The restore comment at :4796 describes this exact two-gateway outcome.- When
find_listener_pidreturns the "1" placeholder (:543-585) and no record exists, setup dies withdie_unknown_listener_ownereven with lsof/ss installed; there's no cmdline fallback.
Fix sketch: in scoped restore, read the major's GATEWAY_PORT, stop the recorded PID, and die non-zero if it can't be stopped. In --status, require a live recorded PID with a matching exe. In start_gateway, stop the old persisted port's recorded gateway on change.
Scope decisions:
- Sub-item 3 under
--no-enable: setup leaves the old port's gateway running and warns with the port.--no-enablemeans "don't change the gateway's running state"; stopping it would leave nothing listening on either port. - Sub-item 4 is deferred to its own change. A cmdline fallback can't tell which major owns the port on a multi-major host (every gateway has the same command line except its config path), so it risks stopping another major's gateway. A correct fix needs config-path matching. Until then setup keeps failing with a clear error rather than guessing.
Related: #727.
3. Reset and package removal report success while PostgreSQL or the gateway is still running (non-systemd)
On a host without systemd, three teardown paths exit 0 while a postmaster or gateway keeps running. Related to #727, which covers only documentdb-setup --restore.
-
documentdb-local-reset --confirm-destroy:documentdb-local/scripts/documentdb-local-reset.sh:232-250only runspg_ctl stopand the live-postmaster check when${data_dir}/postmaster.pidexists. If the data dir is already gone, or the major was never installed, both are skipped. The[[ -d ]]-guarded removals (253-285) become no-ops and line 294 prints "completely reset" regardless. Repro:documentdb-setup,rm -rf /var/lib/documentdb-local/18/data, then reset prints success and exits 0 while the postgres process and port 9718 are still up. A never-installed major also reports success. -
DEB
prermfordocumentdb-N(packaging/standalone/build-standalone-deb.sh:236-250) and the gatewayprerm(documentdb-local/maintainer-scripts/gateway/prerm:24-33) only stop things when systemd is present. The RPM%preuninpackaging/rpm/spec/documentdb-gateway.spec:146-162has the same gate.apt purgetherefore leaves the nohup gateway and postgres serving from deleted binaries and config. -
autoremovecan dropdocumentdb-gatewaywhile it keeps serving, same cause.
Suggested fix: reset locates the postmaster without relying on PGDATA (the pid file, then pgrep/port), stops it, verifies nothing is left, and prints a distinct message when there is nothing to reset. On non-systemd hosts, prerm stops the processes it started (fast, then immediate shutdown) and warns if one survives.
Scope decision: removal never refuses. That matches the systemd branch of the same scripts (systemctl stop ... || true) and Debian's postgresql packages. A process that survives an immediate shutdown is usually mid-checkpoint, where blocking apt/dnf and telling the operator to kill it is worse than a warning.
4. documentdb-setup re-run resets DOCUMENTDB_LISTEN_ADDR to a wildcard bind and never updates documentdb_core
Two silent day-2 problems in documentdb-setup re-runs.
1. Re-run overwrites a restricted bind address. default_gateway_settings_from_persisted_state (documentdb-local/scripts/documentdb-setup.sh:2243) restores only the port and TLS keys. Then documentdb-setup.sh:2364 always passes --listen-addr ":${GATEWAY_PORT}", and write_gateway_env_fragment (documentdb-register-gateway.sh:1230-1244) rewrites the managed block via rewrite_with_managed_block (documentdb-tools-lib.sh:371), which appends the new block last. So DOCUMENTDB_LISTEN_ADDR=127.0.0.1:10260 becomes :10260 (all interfaces), exit 0, no warning. --status (documentdb-setup.sh:4252-4266) prints only the port, so the change is invisible.
2. documentdb_core is never updated. The wizard runs ALTER EXTENSION documentdb UPDATE (:3235) and ALTER EXTENSION documentdb_extended_rum UPDATE (:3242), but not documentdb_core. After a package upgrade plus re-run, documentdb moves to the new version while documentdb_core stays on the old catalog version. --status shows no extension versions either.
Suggested fix
- Restore the persisted
DOCUMENTDB_LISTEN_ADDRhost the same way the port/TLS are restored, with a "Keeping gateway bind address ..." log line. - Run
ALTER EXTENSION documentdb_core UPDATEbeforedocumentdb(same transaction). - Print the bind address and installed
documentdb_core/documentdb/documentdb_extended_rumversions in--status. - Add tests for both in
documentdb_local_tests/test_documentdb_setup.py.
Related: #732 (installer day-2 diagnostics).
5. documentdb-setup configures a major with no documentdb-N package; apt autoremove can then remove a running install
documentdb-setup --pg-version N only checks that PG binaries and documentdb.control exist (documentdb-local/scripts/documentdb-setup.sh:1532, :2036); the only major gate is >= 16 (:2591). It never checks that documentdb-N is installed. Since documentdb-common is held only by documentdb-N's Depends (packaging/standalone/build-standalone-deb.sh), it stays auto-installed for another major only.
Repro (Debian/Ubuntu):
apt-get install postgresql-17-documentdb documentdb-18
documentdb-setup ... --pg-version 17 # succeeds, gateway on 10260
apt-get purge --autoremove documentdb-18 postgresql-18-documentdb
documentdb-common, gateway and tools get autoremoved. The PG17 gateway keeps running from a deleted binary, and documentdb-setup / documentdb-local-reset are gone.
Also: build-common-deb.sh:159 has an unversioned Replaces: documentdb-16, documentdb-17, documentdb-18 with no Breaks, so apt offers documentdb-common as a substitute for a missing documentdb-N. The comment above it says the pre-split package never shipped.
Suggested fix:
- In setup, require
documentdb-<major>(dpkg-query / rpm -q) whendocumentdb-commonis package-managed; die or warn. - Drop that
Replaces, or pair it with aBreaks. - Optionally
apt-mark manual documentdb-commonat setup.
6. documentdb-gateway --check reports OK when pg_hba/pg_ident changes haven't been reloaded
documentdb-gateway --check can print check OK and exit 0 while every client request would fail peer authentication.
Why: run_check (pg_documentdb_gw/documentdb_gateway/src/check.rs:27-62) calls create_connection_pool_manager, whose validate_startup_pools (pool_manager.rs:387-396) only touches the SystemRequests and PreAuthRequests pools. Those connect as postgres_system_user (pool_manager.rs:332-345), i.e. the URL-file role, which works with plain same-name peer auth before any reload. check.rs then queries pg_extension on that same system pool.
Client requests use a different path: allocate_data_pool (auth.rs:576, auth.rs:770, context/connection.rs:245-254) connects as the authenticated user, relying on the managed peer map=documentdb-gateway-map rule written by documentdb-local/scripts/documentdb-register-gateway.sh:420. That rule is only active after a PostgreSQL reload, which the script just prints as a remaining step (:695, :742). --check never exercises it.
Repro: run documentdb-register-gateway, skip the reload, run documentdb-gateway --check (OK), then connect with a client (peer auth failure).
packaging/gateway/packaging-design.md:166 claims a green --check "strongly implies a successful service start"; not true here. test-gateway-install-entrypoint.sh only checks the happy path after reload.
Fix idea: after the system-pool query, open a throwaway data-pool connection as a role covered by the managed hba/ident entries (e.g. a member of documentdb_admin_role) and run SELECT 1. On failure, print the role and hint at systemctl reload postgresql@<N>-<cluster>. Add a negative test: register, no reload, --check must fail; reload, must pass.
Activity
guanzhousongmicrosoft commentedon Oct 5, 2026
Plan: items 1-4 go in 1.0-RC2, together with #727. Items 5 and 6 go in 1.0.
guanzhousongmicrosoft commentedon Oct 6, 2026
1.0 blockers: items 1-4. The fix is in review. Items 5 and 6 don't block 1.0.
Merged PR 2342109: packaging: stop documentdb-setup, reset and packag…
documentdb-triage-tool commentedon Oct 28, 2026
👋 @guanzhousongmicrosoft — this issue has been assigned for 22 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.
documentdb-triage-tool commentedon Nov 11, 2026
👋 @guanzhousongmicrosoft — this issue has been assigned for 14 days with no activity. Is it still in progress? If you've made progress, please leave a quick update. Otherwise it'll be flagged for re-assignment at the next triage meeting.
Merged PR 2343171: packaging: fix remove, purge, upgrade and rerun pa…
guanzhousongmicrosoft commentedon Nov 23, 2026
Items 1–5 are fixed on main (1e882d8, eca4171, b566aa3), with sub-item 2.4 deferred. Item 6,
documentdb-gateway --checkpassing while client-pool peer auth would still fail, is still open.