Skip to content

Commit 73d22d8

Browse files
docs: complete advanced package operations guidance
Document brownfield adoption and safe no-systemd detach behavior, move unattended details out of the quick start, and avoid inferring package version suffixes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ed25bd3e-4cfc-4ee1-b8ee-7733474cc141 Signed-off-by: Guanzhou Song <guanzhousong@microsoft.com>
1 parent 25ab647 commit 73d22d8

4 files changed

Lines changed: 226 additions & 38 deletions

File tree

‎PACKAGE-INSTALL.md‎

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ sudo documentdb-setup --pg-version 18 --use-new-postgres-instance --admin-user a
139139

140140
The explicit major and fresh-instance flags prevent another installed PostgreSQL major or an
141141
existing system cluster from being selected accidentally. To adopt an existing PostgreSQL
142-
instance instead, use the brownfield workflow in the advanced operations documentation.
142+
instance instead, use [Adopt an existing PostgreSQL instance](#adopt-an-existing-postgresql-instance).
143143

144144
`mongosh` is not shipped by these packages. Install it from the
145145
[official instructions](https://www.mongodb.com/docs/mongodb-shell/install/), then:
@@ -227,15 +227,42 @@ On hosts without systemd (containers, some dev images) the wizard starts the gat
227227
instead; the `systemctl` commands above fail with *"System has not been booted with systemd"*.
228228
Use `documentdb-setup --status` to inspect it and re-run `documentdb-setup` to restart it.
229229

230-
**Running SQL against the managed instance.** The private PostgreSQL instance is owned by the
231-
`documentdb-local` system user and listens on a socket, so a bare `psql` will not find it:
230+
### Adopt an existing PostgreSQL instance
231+
232+
Use brownfield mode only when PostgreSQL already exists and its service and data remain
233+
operator-owned. Back up the instance first. The wizard does not create, delete, start, or stop
234+
that PostgreSQL instance, but it does add managed configuration blocks, create the gateway role,
235+
install the DocumentDB extensions, and register the gateway.
236+
237+
Identify the instance as `<major>/<name>`. On Ubuntu, run `pg_lsclusters`; a typical instance is
238+
`18/main`. The standard PGDG layout on EL9 has one instance per major and also uses `18/main`;
239+
add `--pg-port` when it listens on a non-default port.
240+
241+
```bash
242+
sudo documentdb-setup --target-postgres-instance 18/main --admin-user admin
243+
```
244+
245+
If `shared_preload_libraries` changed, the first run prints a restart handoff instead of
246+
finishing setup. Restart the operator-managed PostgreSQL service, then re-run the exact setup
247+
command it prints. Typical service names are `postgresql@18-main.service` on Ubuntu and
248+
`postgresql-18.service` on EL9. The wizard intentionally does not restart an adopted PostgreSQL
249+
instance for you.
250+
251+
The wizard's default `default_toast_compression` setting applies to newly written values in
252+
every database on an adopted instance. If other workloads must retain PostgreSQL's own default,
253+
prefix both setup runs with `sudo DOCUMENTDB_TOAST_COMPRESSION=default`.
254+
255+
**Running SQL against a package-managed private instance.** A greenfield PostgreSQL instance is
256+
owned by the `documentdb-local` system user and listens on a socket, so a bare `psql` will not
257+
find it:
232258

233259
```bash
234260
sudo -u documentdb-local psql -h /run/documentdb-local/18/postgresql -p 9718 -d postgres
235261
```
236262

237263
Use that connection for the `ALTER EXTENSION` statements under Upgrading, and to read versions
238264
with `SELECT extname, extversion FROM pg_extension WHERE extname LIKE 'documentdb%';`.
265+
For an adopted instance, use the operator's existing PostgreSQL connection instead.
239266

240267
**Greenfield: destroy the package-managed instance:**
241268

@@ -252,9 +279,41 @@ sudo dnf remove documentdb-18 postgresql18-documentdb && sudo dnf autoremove
252279

253280
**Brownfield: detach without deleting the existing PostgreSQL instance:**
254281

282+
Before restoring, run `sudo documentdb-setup --status` and note the gateway port for the major
283+
you are removing.
284+
285+
On a systemd host, a scoped restore stops and disables that major's gateway:
286+
255287
```bash
256288
sudo documentdb-setup --restore --pg-version 18
289+
```
290+
291+
On a host without systemd, v0.116 cannot safely attribute a nohup gateway process to one
292+
PostgreSQL major. If only one DocumentDB major is configured, use an unscoped restore so the
293+
orphan gateway sweep runs:
257294

295+
```bash
296+
sudo documentdb-setup --restore --yes
297+
```
298+
299+
If more than one DocumentDB major is configured without systemd, schedule a maintenance window
300+
and use the same unscoped restore. It detaches every configured major and stops the nohup
301+
gateways; re-run setup for the majors you are keeping afterward. A scoped restore alone is not
302+
sufficient on a no-systemd host.
303+
304+
Restart the adopted PostgreSQL service after restore to apply removal of the managed settings.
305+
On an unscoped multi-major restore, restart each operator-managed PostgreSQL service involved.
306+
307+
Verify that the target gateway port is no longer listening before removing packages. Substitute
308+
the port you noted above; the command should produce no output:
309+
310+
```bash
311+
ss -lnt | grep ':10260'
312+
```
313+
314+
Then remove the selected major:
315+
316+
```bash
258317
sudo apt purge --autoremove documentdb-18 postgresql-18-documentdb
259318
sudo dnf remove documentdb-18 postgresql18-documentdb && sudo dnf autoremove
260319
```

‎app/packages/page.tsx‎

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ export default function PackagesPage() {
104104
const latestReleaseAptVersion = release.aptVersion;
105105
const latestReleaseRpmVersion = release.rpmVersion;
106106
const packagingGuideUrl = `https://github.com/documentdb/documentdb/blob/${release.tagName}/packaging/README.md`;
107-
// The repository serves the mirrored release, so the pinning examples use the
108-
// same versions rather than a separately maintained pair that fell behind.
109-
const repoAptVersionExample = release.aptVersion;
110-
const repoRpmVersionExample = release.rpmVersion;
111107
const currentReleaseExamples = [
112108
`ubuntu24.04-documentdb_${release.metaVersion}_all.deb`,
113109
`ubuntu24.04-postgresql-18-documentdb_${latestReleaseAptVersion}_amd64.deb`,
@@ -373,9 +369,14 @@ export default function PackagesPage() {
373369
or an existing system cluster cannot be selected by accident. It installs
374370
the extensions, bootstraps the admin user and starts the gateway — the
375371
package install above on its own does not leave a reachable endpoint. It
376-
prompts for the admin password; pass{" "}
377-
<code className="text-gray-300">--admin-password-stdin --yes</code> for an
378-
unattended install.
372+
prompts for the admin password. For automation, use the complete{" "}
373+
<Link
374+
className="text-blue-400 hover:text-blue-300"
375+
href="/docs/linux-packages#unattended-setup"
376+
>
377+
unattended setup
378+
</Link>{" "}
379+
instructions.
379380
</p>
380381
<CommandSnippet
381382
command={buildSetupCommand(
@@ -569,17 +570,10 @@ export default function PackagesPage() {
569570
selected target actually installs.
570571
</p>
571572
<p className="text-sm text-amber-300">
572-
The two package families carry <strong>different version strings</strong>, so the
573-
right <code className="text-gray-300">&lt;VERSION&gt;</code> depends on which you
574-
pin. The extension is{" "}
575-
<code className="text-gray-300">{repoAptVersionExample}</code> (APT) /{" "}
576-
<code className="text-gray-300">{repoRpmVersionExample}</code> (RPM), while{" "}
577-
<code className="text-gray-300">documentdb</code>,{" "}
578-
<code className="text-gray-300">documentdb-&lt;pg&gt;</code> and the gateway are{" "}
579-
<code className="text-gray-300">{release.metaVersion}</code> (APT) /{" "}
580-
<code className="text-gray-300">{release.metaRpmVersion}</code> (RPM). Pinning{" "}
581-
<code className="text-gray-300">documentdb-18={repoAptVersionExample}</code>{" "}
582-
fails — always take the string the list command prints.
573+
APT and RPM use different version syntax, and individual subpackages can carry
574+
different release suffixes. Always copy the exact version returned below for{" "}
575+
<code className="text-gray-300">{selectedPackageNames}</code>; do not infer it
576+
from the extension or another package.
583577
</p>
584578
<div>
585579
<p className="mb-1 text-xs font-semibold text-gray-400">APT — list then pin</p>

‎app/services/articleService.ts‎

Lines changed: 79 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ If something does not work as expected:
161161
- [Package Finder](/packages)
162162
`;
163163

164-
const linuxPackagesGuideContent = `# Linux Packages Quick Start
164+
export const linuxPackagesGuideContent = `# Linux Packages Quick Start
165165
166166
Install DocumentDB from the published package repository and get a MongoDB-compatible endpoint on your own host.
167167
@@ -241,14 +241,7 @@ ${buildSetupCommand('18')}
241241
242242
It creates a new private PostgreSQL 18 instance, installs the extensions, starts the gateway, and enables it at boot. It **prompts for the admin password**. The explicit major and fresh-instance flags keep another installed PostgreSQL major or an existing system cluster from being selected accidentally.
243243
244-
In a non-interactive shell, the command exits unless you provide a password source:
245-
246-
\`\`\`bash
247-
printf '%s' "$ADMIN_PW" | sudo documentdb-setup --pg-version 18 \\
248-
--use-new-postgres-instance --admin-user admin --admin-password-stdin --yes
249-
\`\`\`
250-
251-
To adopt an existing PostgreSQL instance instead, follow [Operating a package install](/docs/linux-packages); brownfield setup intentionally has different lifecycle and restart requirements.
244+
For automation, use the complete [unattended setup](/docs/linux-packages#unattended-setup) command. To adopt an existing PostgreSQL instance instead, follow [Adopt an existing PostgreSQL instance](/docs/linux-packages#adopt-an-existing-postgre-sql-instance); brownfield setup intentionally has different lifecycle and restart requirements.
252245
253246
Now open a shell against the endpoint:
254247
@@ -287,7 +280,7 @@ A database and collection are created on first write:
287280
More failure modes, including hosts without systemd: [Operating a package install](/docs/linux-packages#troubleshooting).
288281
`;
289282

290-
const linuxPackagesOperationsContent = `# Operating a package install
283+
export const linuxPackagesOperationsContent = `# Operating a package install
291284
292285
Day-2 operations for a DocumentDB installed from Linux packages: securing the endpoint, managing services, running SQL, upgrading, and removal. Install first with the [Linux Packages Quick Start](/docs/getting-started/packages).
293286
@@ -343,9 +336,35 @@ sudo systemctl restart documentdb-local@18.target
343336
sudo systemctl stop documentdb-local@18.target
344337
\`\`\`
345338
346-
## Running SQL against the managed instance
339+
## Adopt an existing PostgreSQL instance
340+
341+
Use brownfield mode only when PostgreSQL already exists and its service and data remain
342+
operator-owned. Back up the instance first. The wizard does not create, delete, start, or stop
343+
that PostgreSQL instance, but it does add managed configuration blocks, create the gateway role,
344+
install the DocumentDB extensions, and register the gateway.
345+
346+
Identify the instance as \`<major>/<name>\`. On Ubuntu, run \`pg_lsclusters\`; a typical instance
347+
is \`18/main\`. The standard PGDG layout on EL9 has one instance per major and also uses
348+
\`18/main\`; add \`--pg-port\` when it listens on a non-default port.
349+
350+
\`\`\`bash
351+
sudo documentdb-setup --target-postgres-instance 18/main --admin-user admin
352+
\`\`\`
353+
354+
If \`shared_preload_libraries\` changed, the first run prints a restart handoff instead of
355+
finishing setup. Restart the operator-managed PostgreSQL service, then re-run the exact setup
356+
command it prints. Typical service names are \`postgresql@18-main.service\` on Ubuntu and
357+
\`postgresql-18.service\` on EL9. The wizard intentionally does not restart an adopted
358+
PostgreSQL instance for you.
359+
360+
The wizard's default \`default_toast_compression\` setting applies to newly written values in
361+
every database on an adopted instance. If other workloads must retain PostgreSQL's own default,
362+
prefix both setup runs with \`sudo DOCUMENTDB_TOAST_COMPRESSION=default\`.
363+
364+
## Running SQL against a package-managed private instance
347365
348-
\`documentdb-setup\` runs a private instance as the \`documentdb-local\` user on a socket, so a bare \`psql\` will not find it:
366+
A greenfield PostgreSQL instance runs as the \`documentdb-local\` user on a socket, so a bare
367+
\`psql\` will not find it:
349368
350369
\`\`\`bash
351370
sudo -u documentdb-local psql -h /run/documentdb-local/18/postgresql -p 9718 -d postgres
@@ -355,6 +374,8 @@ sudo -u documentdb-local psql -h /run/documentdb-local/18/postgresql -p 9718 -d
355374
SELECT extname, extversion FROM pg_extension WHERE extname LIKE 'documentdb%';
356375
\`\`\`
357376
377+
For an adopted instance, use the operator's existing PostgreSQL connection instead.
378+
358379
## Upgrading
359380
360381
> [!WARNING]
@@ -418,9 +439,41 @@ sudo dnf remove documentdb-18 postgresql18-documentdb && sudo dnf autoremove
418439
419440
### Brownfield: detach from an existing PostgreSQL instance
420441
442+
Before restoring, run \`sudo documentdb-setup --status\` and note the gateway port for the major
443+
you are removing.
444+
445+
On a systemd host, a scoped restore stops and disables that major's gateway:
446+
421447
\`\`\`bash
422448
sudo documentdb-setup --restore --pg-version 18
449+
\`\`\`
423450
451+
On a host without systemd, v0.116 cannot safely attribute a nohup gateway process to one
452+
PostgreSQL major. If only one DocumentDB major is configured, use an unscoped restore so the
453+
orphan gateway sweep runs:
454+
455+
\`\`\`bash
456+
sudo documentdb-setup --restore --yes
457+
\`\`\`
458+
459+
If more than one DocumentDB major is configured without systemd, schedule a maintenance window
460+
and use the same unscoped restore. It detaches every configured major and stops the nohup
461+
gateways; re-run setup for the majors you are keeping afterward. A scoped restore alone is not
462+
sufficient on a no-systemd host.
463+
464+
Restart the adopted PostgreSQL service after restore to apply removal of the managed settings.
465+
On an unscoped multi-major restore, restart each operator-managed PostgreSQL service involved.
466+
467+
Verify that the target gateway port is no longer listening before removing packages. Substitute
468+
the port you noted above; the command should produce no output:
469+
470+
\`\`\`bash
471+
ss -lnt | grep ':10260'
472+
\`\`\`
473+
474+
Then remove the selected major:
475+
476+
\`\`\`bash
424477
sudo apt purge --autoremove documentdb-18 postgresql-18-documentdb
425478
sudo dnf remove documentdb-18 postgresql18-documentdb && sudo dnf autoremove
426479
\`\`\`
@@ -429,9 +482,8 @@ Do not run \`documentdb-local-reset\` for brownfield installations: the PostgreS
429482
its data belong to the operator. Do not run restore before a greenfield reset either; restore
430483
deletes the state that identifies custom data directories and protects adopted clusters.
431484
432-
Confirm the stack is down with \`ss -lnt | grep 10260\`. On a multi-major host remove one major
433-
at a time and re-check the survivor: \`documentdb-common\` owns the shared tooling and only
434-
\`documentdb-N\` holds it.
485+
On a systemd multi-major host, remove one major at a time and re-check the survivor:
486+
\`documentdb-common\` owns the shared tooling and only \`documentdb-N\` holds it.
435487
436488
## Known issues in 0.116
437489
@@ -442,7 +494,7 @@ These are defects in this release, not expected behaviour. Most need a host with
442494
| Status | \`documentdb-setup --status\` can report "active" for any process holding port 10260 | **any host** |
443495
| Upgrade | \`documentdb-setup\` does not run \`ALTER EXTENSION documentdb_core UPDATE\`; run it yourself | **any host** |
444496
| Restart | Re-running \`documentdb-setup\` to restart can hang; redirecting output to a file avoids it | no systemd |
445-
| Stop | \`documentdb-setup --restore --pg-version N\` reports success without stopping the gateway — use an unscoped \`--restore\`, which stops every major on the host | no systemd |
497+
| Stop | A scoped \`documentdb-setup --restore --pg-version N\` cannot stop a nohup gateway; follow the no-systemd brownfield removal steps above | no systemd |
446498
| Minimal RHEL | Install \`procps-ng\` first, or \`--restore\` reports success while the gateway keeps serving and a later run fails with \`Port 10260 is already in use\` | no systemd |
447499
448500
**Prefer a systemd host for anything you care about**, where the service lifecycle is managed by systemd rather than by the setup script.
@@ -474,7 +526,17 @@ Failure modes beyond the four in the [quick start](/docs/getting-started/package
474526
475527
## Unattended setup
476528
477-
\`documentdb-setup\` prompts for the admin password. For servers and CI, pass \`--admin-password-file <file>\` or \`--admin-password-stdin\` together with \`--yes\`.
529+
\`documentdb-setup\` prompts for the admin password. For servers and CI, provide exactly one
530+
password source and pass \`--yes\`. For a new private instance:
531+
532+
\`\`\`bash
533+
printf '%s' "$ADMIN_PW" | sudo documentdb-setup --pg-version 18 \\
534+
--use-new-postgres-instance --admin-user admin --admin-password-stdin --yes
535+
\`\`\`
536+
537+
For brownfield adoption, replace \`--pg-version 18 --use-new-postgres-instance\` with
538+
\`--target-postgres-instance 18/main\`. You can use
539+
\`--admin-password-file /path/to/protected/file\` instead of stdin.
478540
`;
479541

480542
const linuxPackagesOfflineContent = `# Offline / air-gapped install

‎tests/packageArticles.test.ts‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { describe, expect, it } from 'vitest';
2+
import {
3+
linuxPackagesGuideContent,
4+
linuxPackagesOperationsContent,
5+
} from '../app/services/articleService';
6+
7+
describe('Linux package articles', () => {
8+
it('keeps advanced setup details out of the quick start', () => {
9+
expect(linuxPackagesGuideContent).toContain(
10+
'/docs/linux-packages#unattended-setup',
11+
);
12+
expect(linuxPackagesGuideContent).toContain(
13+
'/docs/linux-packages#adopt-an-existing-postgre-sql-instance',
14+
);
15+
expect(linuxPackagesGuideContent).not.toContain('--admin-password-stdin');
16+
expect(linuxPackagesGuideContent).not.toContain('--target-postgres-instance');
17+
});
18+
19+
it('documents the supported brownfield adoption workflow', () => {
20+
expect(linuxPackagesOperationsContent).toContain(
21+
'## Adopt an existing PostgreSQL instance',
22+
);
23+
expect(linuxPackagesOperationsContent).toContain(
24+
'sudo documentdb-setup --target-postgres-instance 18/main --admin-user admin',
25+
);
26+
expect(linuxPackagesOperationsContent).toContain(
27+
'The wizard intentionally does not restart an adopted',
28+
);
29+
expect(linuxPackagesOperationsContent).toContain(
30+
'DOCUMENTDB_TOAST_COMPRESSION=default',
31+
);
32+
});
33+
34+
it('distinguishes scoped systemd restore from no-systemd cleanup', () => {
35+
expect(linuxPackagesOperationsContent).toContain(
36+
'sudo documentdb-setup --restore --pg-version 18',
37+
);
38+
expect(linuxPackagesOperationsContent).toContain(
39+
'sudo documentdb-setup --restore --yes',
40+
);
41+
expect(linuxPackagesOperationsContent).toMatch(
42+
/A scoped restore alone is not\s+sufficient on a no-systemd host\./,
43+
);
44+
expect(linuxPackagesOperationsContent).toContain(
45+
'Restart the adopted PostgreSQL service after restore',
46+
);
47+
expect(linuxPackagesOperationsContent).toContain(
48+
"the command should produce no output",
49+
);
50+
});
51+
52+
it('provides a complete unattended setup command', () => {
53+
expect(linuxPackagesOperationsContent).toContain(
54+
`printf '%s' "$ADMIN_PW" | sudo documentdb-setup --pg-version 18`,
55+
);
56+
expect(linuxPackagesOperationsContent).toContain(
57+
'--use-new-postgres-instance --admin-user admin --admin-password-stdin --yes',
58+
);
59+
});
60+
61+
it('keeps Package Finder advanced hints linked and version-agnostic', async () => {
62+
const { readFile } = await import('node:fs/promises');
63+
const { fileURLToPath } = await import('node:url');
64+
const source = await readFile(
65+
fileURLToPath(new URL('../app/packages/page.tsx', import.meta.url)),
66+
'utf8',
67+
);
68+
69+
expect(source).toContain('href="/docs/linux-packages#unattended-setup"');
70+
expect(source).toContain('individual subpackages can carry');
71+
expect(source).not.toContain('and the gateway are');
72+
});
73+
});

0 commit comments

Comments
 (0)