@bastani/atomic 0.10.14 → 0.10.15-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/README.md +1 -1
- package/dist/_shared/dist-KOELCESV.js +2 -2
- package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
- package/dist/_shared/lib-4PES5P4V.js +2 -2
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +3 -3
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +3 -3
- package/dist/_shared/mode-shared-2QJSCUM6.js +3 -3
- package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
- package/dist/_shared/runtime-O4KCSG4C.js +2 -2
- package/dist/_shared/{sdk-B5LEWGGI.js → sdk-OHKMDJ74.js} +27 -5
- package/dist/_shared/{sdk-B5LEWGGI.js.map → sdk-OHKMDJ74.js.map} +1 -1
- package/dist/_shared/session-data-AHTU7IS6.js +2 -2
- package/dist/_shared/startup-0-0-Q3MWKUK4.js +2 -2
- package/dist/_shared/startup-0-1-M6OWAYHH.js +2 -2
- package/dist/_shared/{startup-0-2-5QHPCEON.js → startup-0-2-2HUMCPKX.js} +14 -16
- package/dist/_shared/startup-0-2-2HUMCPKX.js.map +1 -0
- package/dist/_shared/startup-0-3-4ZYBYQNM.js +3 -3
- package/dist/_shared/startup-0-4-ZMJV547D.js +3 -3
- package/dist/_shared/startup-0-5-YDW47QX6.js +3 -3
- package/dist/_shared/startup-10-0-TDQNBDDL.js +3 -3
- package/dist/_shared/startup-14-0-MLX36RBG.js +1 -1
- package/dist/_shared/startup-15-0-YUKGAC63.js +1 -1
- package/dist/_shared/startup-15-1-4S7FLMNG.js +6 -30
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +3 -3
- package/dist/_shared/startup-8-1-LZFXSD3Z.js +3 -3
- package/dist/_shared/storage-command-7MGXLJGZ.js +2 -2
- package/dist/_shared/storage-status-K7PX2RXA.js +3 -3
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
- package/dist/builtin/intercom/index.bundle.mjs +1 -1
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/index.bundle.mjs +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/cli/auth-cli.code.js +1 -1
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.impl.js +3 -3
- package/dist/cli/blueprint-command.js +3 -3
- package/dist/cli/intercom-command.code.js +3 -3
- package/dist/cli/intercom-command.impl.js +3 -3
- package/dist/cli/intercom-command.js +3 -3
- package/dist/cli/list-models.impl.js +3 -3
- package/dist/cli/list-models.js +3 -3
- package/dist/cli/session-picker.code.js +1 -1
- package/dist/cli/session-picker.impl.js +3 -3
- package/dist/cli/session-picker.js +3 -3
- package/dist/cli/startup-ui.code.js +1 -1
- package/dist/cli/startup-ui.impl.js +3 -3
- package/dist/cli/startup-ui.js +3 -3
- package/dist/cli/storage-command.impl.js +3 -3
- package/dist/cli/storage-command.js +3 -3
- package/dist/cli/storage-search-session.code.js +1 -1
- package/dist/cli/storage-search-session.impl.js +3 -3
- package/dist/cli/storage-search-session.js +3 -3
- package/dist/cli/team-command.code.js +1 -1
- package/dist/cli/team-command.impl.js +3 -3
- package/dist/cli/team-command.js +3 -3
- package/dist/cli.js +2 -2
- package/dist/core/compaction/compactor.d.ts +0 -8
- package/dist/core/debug.impl.js +3 -3
- package/dist/core/debug.js +3 -3
- package/dist/core/export-html/card-projection.impl.js +3 -3
- package/dist/core/export-html/card-projection.js +3 -3
- package/dist/core/export-html/index.code.js +2 -2
- package/dist/core/export-html/index.impl.js +3 -3
- package/dist/core/export-html/index.js +3 -3
- package/dist/core/export-html/json-spans.impl.js +3 -3
- package/dist/core/export-html/json-spans.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.js +3 -3
- package/dist/core/export-html/tool-renderer.impl.js +3 -3
- package/dist/core/export-html/tool-renderer.js +3 -3
- package/dist/core/extensions/jiti-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-loader.js +3 -3
- package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-static-loader.js +3 -3
- package/dist/core/extensions/loader-host-modules.impl.js +3 -3
- package/dist/core/extensions/loader-host-modules.js +3 -3
- package/dist/core/intercom-broker-control-host.code.js +1 -1
- package/dist/core/intercom-broker-control-host.impl.js +3 -3
- package/dist/core/intercom-broker-control-host.js +3 -3
- package/dist/core/intercom-broker-control.code.js +2 -2
- package/dist/core/intercom-broker-control.impl.js +3 -3
- package/dist/core/intercom-broker-control.js +3 -3
- package/dist/core/package-manager-storage-adapters.impl.js +3 -3
- package/dist/core/package-manager-storage-adapters.js +3 -3
- package/dist/core/sdk.code.js +1 -1
- package/dist/core/sdk.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-manager-core.js +3 -3
- package/dist/core/session-manager-list.impl.js +3 -3
- package/dist/core/session-manager-list.js +3 -3
- package/dist/core/session-manager.impl.js +3 -3
- package/dist/core/session-manager.js +3 -3
- package/dist/core/session-storage.impl.js +3 -3
- package/dist/core/session-storage.js +3 -3
- package/dist/core/storage/index.js +2 -2
- package/dist/core/storage/node-sqlite-thread.js +2 -2
- package/dist/core/storage/node-sqlite.js +2 -2
- package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
- package/dist/core/storage/offline-snapshot-file.js +3 -3
- package/dist/core/storage/provider.js +2 -2
- package/dist/core/storage/selection.js +2 -2
- package/dist/core/storage/session/branch-fork-source.code.js +2 -2
- package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
- package/dist/core/storage/session/branch-fork-source.js +3 -3
- package/dist/core/storage/session/card-view.impl.js +3 -3
- package/dist/core/storage/session/card-view.js +3 -3
- package/dist/core/storage/session/child-reader.code.js +2 -2
- package/dist/core/storage/session/child-reader.impl.js +3 -3
- package/dist/core/storage/session/child-reader.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.js +3 -3
- package/dist/core/storage/session/expanded-child-details.code.js +2 -2
- package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
- package/dist/core/storage/session/expanded-child-details.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.js +3 -3
- package/dist/core/storage/session/fork-row-index.impl.js +3 -3
- package/dist/core/storage/session/fork-row-index.js +3 -3
- package/dist/core/storage/session/fork-staging.code.js +1 -1
- package/dist/core/storage/session/fork-staging.impl.js +3 -3
- package/dist/core/storage/session/fork-staging.js +3 -3
- package/dist/core/storage/session/fork-window.code.js +2 -2
- package/dist/core/storage/session/fork-window.impl.js +3 -3
- package/dist/core/storage/session/fork-window.js +3 -3
- package/dist/core/storage/session/history-pages.impl.js +3 -3
- package/dist/core/storage/session/history-pages.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.js +3 -3
- package/dist/core/storage/session/memory-session-store.impl.js +3 -3
- package/dist/core/storage/session/memory-session-store.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.code.js +2 -2
- package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.js +3 -3
- package/dist/core/storage/session/released-history-files.code.js +1 -1
- package/dist/core/storage/session/released-history-files.impl.js +3 -3
- package/dist/core/storage/session/released-history-files.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.js +3 -3
- package/dist/core/storage/session/session-resume.impl.js +3 -3
- package/dist/core/storage/session/session-resume.js +3 -3
- package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
- package/dist/core/storage/session/snapshot-cut.js +3 -3
- package/dist/core/storage/session/snapshot-history.code.js +2 -2
- package/dist/core/storage/session/snapshot-history.impl.js +3 -3
- package/dist/core/storage/session/snapshot-history.js +3 -3
- package/dist/core/storage/session/sql-session-store.code.js +1 -1
- package/dist/core/storage/session/sql-session-store.impl.js +3 -3
- package/dist/core/storage/session/sql-session-store.js +3 -3
- package/dist/core/storage/session/tree-outline.impl.js +3 -3
- package/dist/core/storage/session/tree-outline.js +3 -3
- package/dist/core/storage/session/tree-presentation.impl.js +3 -3
- package/dist/core/storage/session/tree-presentation.js +3 -3
- package/dist/core/storage/storage-status.impl.js +3 -3
- package/dist/core/storage/storage-status.js +3 -3
- package/dist/core/storage/team.impl.js +3 -3
- package/dist/core/storage/team.js +3 -3
- package/dist/core/structured-output/index.code.js +1 -1
- package/dist/core/structured-output/index.impl.js +3 -3
- package/dist/core/structured-output/index.js +3 -3
- package/dist/core/tasks/task-completion-entry.impl.js +3 -3
- package/dist/core/tasks/task-completion-entry.js +3 -3
- package/dist/core/tasks/task-file-history.code.js +2 -2
- package/dist/core/tasks/task-file-history.impl.js +3 -3
- package/dist/core/tasks/task-file-history.js +3 -3
- package/dist/core/tasks/task-reference-archive.code.js +2 -2
- package/dist/core/tasks/task-reference-archive.js +3 -3
- package/dist/core/tasks/task-reference-identity.js +3 -3
- package/dist/core/tasks/task-reference-stream.impl.js +3 -3
- package/dist/core/tasks/task-reference-stream.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.js +3 -3
- package/dist/core/tasks/task-view-source.impl.js +3 -3
- package/dist/core/tasks/task-view-source.js +3 -3
- package/dist/core/tools/read-url.impl.js +3 -3
- package/dist/core/tools/read-url.js +3 -3
- package/dist/core/worktree-snapshot/blob-store.js +2 -2
- package/dist/core/worktree-snapshot/errors.code.js +1 -1
- package/dist/core/worktree-snapshot/errors.impl.js +3 -3
- package/dist/core/worktree-snapshot/errors.js +3 -3
- package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
- package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
- package/dist/extensions/codemode/execute.impl.js +3 -3
- package/dist/extensions/codemode/execute.js +3 -3
- package/dist/extensions/codemode/renderer.impl.js +3 -3
- package/dist/extensions/codemode/renderer.js +3 -3
- package/dist/extensions/mcp/cli.code.js +1 -1
- package/dist/extensions/mcp/cli.impl.js +3 -3
- package/dist/extensions/mcp/cli.js +3 -3
- package/dist/extensions/mcp/cli.lazy.code.js +2 -2
- package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
- package/dist/extensions/mcp/cli.lazy.js +3 -3
- package/dist/extensions/mcp/runtime.code.js +1 -1
- package/dist/extensions/mcp/runtime.impl.js +3 -3
- package/dist/extensions/mcp/runtime.js +3 -3
- package/dist/index.d.ts +21 -1
- package/dist/index.js +2 -2
- package/dist/main-first-time-setup.code.js +1 -1
- package/dist/main-first-time-setup.impl.js +3 -3
- package/dist/main-first-time-setup.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
- package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
- package/dist/modes/print-mode.js +1 -1
- package/dist/package-manager-cli.code.js +2 -2
- package/dist/package-manager-cli.impl.js +3 -3
- package/dist/package-manager-cli.js +3 -3
- package/dist/startup-files.json +1 -1
- package/dist/startup-stages/6.js +1 -1
- package/dist/utils/startup-database-spare.code.js +1 -1
- package/dist/utils/startup-database-spare.impl.js +3 -3
- package/dist/utils/startup-database-spare.js +3 -3
- package/dist/utils/tools-manager.impl.js +3 -3
- package/dist/utils/tools-manager.js +3 -3
- package/docs/background-tasks/reference.md +182 -0
- package/docs/background-tasks.md +98 -405
- package/docs/build.md +67 -27
- package/docs/changelog.mdx +11 -1
- package/docs/codemode.md +108 -39
- package/docs/compaction/branch-summaries.md +54 -0
- package/docs/compaction/custom-compactors.md +161 -0
- package/docs/compaction/memory-compaction.md +77 -0
- package/docs/compaction/reference.md +86 -38
- package/docs/compaction.md +51 -252
- package/docs/computer-use.md +169 -321
- package/docs/containerization.md +71 -57
- package/docs/custom-provider/api-reference.md +119 -25
- package/docs/custom-provider/oauth.md +114 -132
- package/docs/custom-provider/override.md +37 -27
- package/docs/custom-provider/registration.md +107 -83
- package/docs/custom-provider/streaming.md +85 -71
- package/docs/custom-provider.md +85 -52
- package/docs/development.md +39 -29
- package/docs/docs.json +80 -67
- package/docs/environment-variables.md +94 -44
- package/docs/extensions/api-reference.md +86 -43
- package/docs/extensions/authoring.md +162 -154
- package/docs/extensions/events.md +80 -25
- package/docs/extensions/examples.md +90 -85
- package/docs/extensions/ui.md +206 -82
- package/docs/extensions.md +79 -108
- package/docs/getting-started/authentication.md +67 -36
- package/docs/getting-started/first-session.md +53 -43
- package/docs/getting-started/installation.md +117 -90
- package/docs/getting-started/project-instructions.md +48 -34
- package/docs/guides/configuration.md +82 -20
- package/docs/guides/non-interactive.md +66 -24
- package/docs/guides/resume-on-any-machine.md +135 -82
- package/docs/guides/team-setup.md +114 -105
- package/docs/guides.md +76 -32
- package/docs/herdr.md +16 -17
- package/docs/how-atomic-works.md +140 -0
- package/docs/index.md +58 -44
- package/docs/intercom/operations.md +141 -151
- package/docs/intercom/reference.md +85 -108
- package/docs/intercom.md +84 -145
- package/docs/json.md +120 -67
- package/docs/keybindings.md +85 -49
- package/docs/libraries/agent-core.md +137 -275
- package/docs/libraries/ai.md +100 -84
- package/docs/libraries/codemode.md +210 -300
- package/docs/libraries/schema.md +59 -53
- package/docs/libraries/storage-postgres.md +49 -35
- package/docs/libraries/telemetry.md +153 -354
- package/docs/libraries/tui.md +265 -393
- package/docs/libraries.md +42 -26
- package/docs/llama-cpp.md +171 -161
- package/docs/mcp-servers.md +90 -51
- package/docs/models/choose-a-model.md +188 -0
- package/docs/models/reference.md +74 -30
- package/docs/models.md +153 -88
- package/docs/orchestration/migrating-workflows.md +23 -16
- package/docs/orchestration/patterns.md +39 -44
- package/docs/orchestration.md +65 -26
- package/docs/packages/authoring.md +51 -29
- package/docs/packages/reference.md +42 -21
- package/docs/packages.md +69 -58
- package/docs/programmatic.md +118 -24
- package/docs/prompt-templates.md +84 -83
- package/docs/providers/reference.md +43 -48
- package/docs/providers.md +219 -451
- package/docs/quickstart.md +140 -120
- package/docs/reference/cli.md +135 -97
- package/docs/reference.md +20 -19
- package/docs/rpc/examples.md +76 -20
- package/docs/rpc/extension-ui.md +64 -38
- package/docs/rpc/protocol.md +361 -110
- package/docs/rpc.md +57 -17
- package/docs/sdk/reference.md +409 -534
- package/docs/sdk/storage.md +53 -13
- package/docs/sdk/structured-decisions.md +82 -56
- package/docs/sdk/web-server.md +57 -43
- package/docs/sdk.md +106 -84
- package/docs/security.md +42 -64
- package/docs/session-format.md +62 -38
- package/docs/sessions.md +99 -214
- package/docs/settings.md +165 -195
- package/docs/shell-aliases.md +9 -6
- package/docs/skills/authoring.md +69 -48
- package/docs/skills/reference.md +51 -20
- package/docs/skills.md +99 -148
- package/docs/slash-commands.md +129 -0
- package/docs/storage/custom-adapters.md +160 -85
- package/docs/storage/jsonl.md +81 -66
- package/docs/storage/postgres/pgbouncer.md +120 -126
- package/docs/storage/postgres/tuning.md +120 -143
- package/docs/storage/postgres.md +314 -330
- package/docs/storage/sqlite.md +71 -42
- package/docs/storage.md +298 -302
- package/docs/subagents/authoring.md +55 -38
- package/docs/subagents/reference.md +73 -33
- package/docs/subagents.md +119 -187
- package/docs/terminal-setup.md +51 -39
- package/docs/themes/reference.md +23 -19
- package/docs/themes.md +142 -127
- package/docs/tmux.md +47 -55
- package/docs/tools.md +147 -109
- package/docs/tui/reference.md +166 -214
- package/docs/tui.md +196 -341
- package/docs/usage.md +118 -138
- package/docs/verification.md +79 -51
- package/docs/web-access.md +121 -101
- package/docs/windows.md +26 -27
- package/docs/worktree-snapshots/reference.md +245 -0
- package/docs/worktree-snapshots.md +71 -259
- package/package.json +8 -8
- package/dist/_shared/startup-0-2-5QHPCEON.js.map +0 -1
- package/docs/guides/intercom.md +0 -32
- package/docs/guides/orchestration.md +0 -28
- package/docs/guides/subagents.md +0 -37
- package/docs/termux.md +0 -118
package/docs/storage/postgres.md
CHANGED
|
@@ -1,380 +1,370 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "PostgreSQL setup"
|
|
3
|
-
sidebarTitle: "
|
|
4
|
-
description: "Share Atomic
|
|
3
|
+
sidebarTitle: "PostgreSQL setup"
|
|
4
|
+
description: "Share Atomic sessions and Intercom across machines, teams, or CI with PostgreSQL 16+: create roles, run migrations, join machines, configure TLS, proxies, poolers, cloud identities, and size connections."
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
Use PostgreSQL when
|
|
7
|
+
Use PostgreSQL when multiple machines need to share sessions and Intercom messages—such as a team, a CI fleet, or one person working across several computers. Every joined machine sees the same sessions and can message agents on other joined machines. For one person on one machine, keep the zero-setup [local SQLite](/storage/sqlite) store.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
**Requirements:**
|
|
10
10
|
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
- TLS, HTTP proxies, poolers, and cloud identities;
|
|
14
|
-
- how many connections Atomic opens, and how to size them for many agents;
|
|
15
|
-
- fixes for common errors.
|
|
11
|
+
- **PostgreSQL 16 or newer.** While the standalone `@bastani/atomic-storage-postgres` adapter connects to PostgreSQL 14+, Atomic's session store requires PostgreSQL 16 or newer (for `IS JSON` and `pg_input_is_valid`).
|
|
12
|
+
- **`@bastani/atomic-storage-postgres`** installed on every machine that connects (see [Join a machine](#join-a-machine)).
|
|
16
13
|
|
|
17
|
-
|
|
14
|
+
Self-hosted PostgreSQL and managed services (Azure Database for PostgreSQL Flexible Server, Azure HorizonDB, Amazon RDS/Aurora, Google Cloud SQL, AlloyDB, Neon, and Supabase) are supported.
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
<Columns cols={2}>
|
|
17
|
+
<Card title="PostgreSQL with PgBouncer" href="/storage/postgres/pgbouncer">
|
|
18
|
+
Put PgBouncer in front when agent processes exceed PostgreSQL's connection limit.
|
|
19
|
+
</Card>
|
|
20
|
+
<Card title="Tune PostgreSQL for many agents" href="/storage/postgres/tuning">
|
|
21
|
+
Server-side memory, huge pages, `pg_stat_statements`, busy tables, and `lz4` compression.
|
|
22
|
+
</Card>
|
|
23
|
+
</Columns>
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
<Note>
|
|
26
|
+
A default PostgreSQL server allows 100 connections, and each Atomic process opens up to 10 (11 for an Intercom broker). If you plan to run more than ~8 processes, read [Tuning for many concurrent agents](#tuning-for-many-concurrent-agents) before scaling out.
|
|
27
|
+
</Note>
|
|
25
28
|
|
|
26
29
|
## Set up the database
|
|
27
30
|
|
|
28
|
-
Atomic
|
|
29
|
-
|
|
30
|
-
- **
|
|
31
|
-
- **
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
3.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
If the runtime role lacks a privilege, or the tables are older than the Atomic release that opens them, opening the database fails with `StorageConfigError` and reason `missing-privilege`. The error names the `GRANT` statement or the `atomic storage migrate` command to run.
|
|
31
|
+
Atomic stores its tables in a dedicated schema named `atomic` rather than `public`. Production deployments use two roles:
|
|
32
|
+
|
|
33
|
+
- **Owner role (`atomic_owner`):** owns the database and `atomic` schema; runs `atomic storage migrate` to create and upgrade tables.
|
|
34
|
+
- **Runtime role (`atomic_runtime`):** used by agent machines; reads and writes rows only and cannot alter or drop schema objects.
|
|
35
|
+
|
|
36
|
+
Every machine can share one runtime role, or you can create one login role per person with the same grants. For quick single-user testing, one role that owns the database is sufficient and creates tables automatically on first open.
|
|
37
|
+
|
|
38
|
+
<Tip>
|
|
39
|
+
Run `atomic storage migrate` once as the owner role before starting a fleet of agents on an empty database. With the schema already in place, agents skip first-open DDL coordination and open in a couple of round trips instead of waiting on each other to initialize tables.
|
|
40
|
+
</Tip>
|
|
41
|
+
|
|
42
|
+
<Steps>
|
|
43
|
+
<Step title="Create the roles and database">
|
|
44
|
+
Connect as a superuser (or your managed service's administrator role) and run:
|
|
45
|
+
|
|
46
|
+
```sql
|
|
47
|
+
CREATE ROLE atomic_owner LOGIN PASSWORD '<owner password>';
|
|
48
|
+
CREATE ROLE atomic_runtime LOGIN PASSWORD '<runtime password>';
|
|
49
|
+
-- On a managed service whose administrator is not a superuser (Azure, RDS, Cloud SQL):
|
|
50
|
+
-- GRANT atomic_owner TO <administrator>;
|
|
51
|
+
CREATE DATABASE atomic OWNER atomic_owner;
|
|
52
|
+
REVOKE ALL ON DATABASE atomic FROM PUBLIC;
|
|
53
|
+
GRANT CONNECT ON DATABASE atomic TO atomic_owner, atomic_runtime;
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
On managed services where the admin role is not a superuser, uncomment the `GRANT` line so the admin can create a database owned by `atomic_owner`.
|
|
57
|
+
</Step>
|
|
58
|
+
<Step title="Allow TLS connections">
|
|
59
|
+
On self-hosted servers, enable TLS first (see [TLS](#tls))—Atomic verifies the server's certificate and hostname by default. Allow agent machines as `atomic_runtime` and your migration host as `atomic_owner` in `pg_hba.conf`, then reload with `SELECT pg_reload_conf();`:
|
|
60
|
+
|
|
61
|
+
```text
|
|
62
|
+
# TYPE DATABASE USER ADDRESS METHOD
|
|
63
|
+
hostssl atomic atomic_runtime 10.0.2.0/24 scram-sha-256
|
|
64
|
+
hostssl atomic atomic_owner 10.0.3.10/32 scram-sha-256
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Managed services enable TLS by default and use firewall or private-network rules instead of `pg_hba.conf`.
|
|
68
|
+
</Step>
|
|
69
|
+
<Step title="Create Atomic's tables with atomic storage migrate">
|
|
70
|
+
On a machine with Atomic installed, install the PostgreSQL adapter, save the owner password in an owner-only file, and run `atomic storage migrate` directly against PostgreSQL (not through a connection pooler):
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
atomic install npm:@bastani/atomic-storage-postgres
|
|
74
|
+
(umask 077; printf 'Owner password: '; read -rs password; printf '\n'; printf '%s' "$password" > ~/atomic-owner-password)
|
|
75
|
+
atomic storage migrate --db 'postgresql://atomic_owner@db.example.com:5432/atomic' --password-file ~/atomic-owner-password
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`--password-file`, `--token-file`, `--auth`, and `--prefix` work only alongside `--db`. Without `--db`, `atomic storage migrate` targets the database configured in this machine's `storage` setting.
|
|
79
|
+
</Step>
|
|
80
|
+
<Step title="Grant runtime privileges">
|
|
81
|
+
Connect to the `atomic` database as `atomic_owner` and run:
|
|
82
|
+
|
|
83
|
+
```sql
|
|
84
|
+
GRANT USAGE ON SCHEMA atomic TO atomic_runtime;
|
|
85
|
+
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA atomic TO atomic_runtime;
|
|
86
|
+
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA atomic TO atomic_runtime;
|
|
87
|
+
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA atomic TO atomic_runtime;
|
|
88
|
+
ALTER DEFAULT PRIVILEGES FOR ROLE atomic_owner IN SCHEMA atomic GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO atomic_runtime;
|
|
89
|
+
ALTER DEFAULT PRIVILEGES FOR ROLE atomic_owner IN SCHEMA atomic GRANT USAGE, SELECT ON SEQUENCES TO atomic_runtime;
|
|
90
|
+
ALTER DEFAULT PRIVILEGES FOR ROLE atomic_owner IN SCHEMA atomic GRANT EXECUTE ON FUNCTIONS TO atomic_runtime;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`ALTER DEFAULT PRIVILEGES` covers objects added by future Atomic upgrades, so you only need to run this step once. Intercom `LISTEN`/`NOTIFY` and advisory locks require no extra grants.
|
|
94
|
+
</Step>
|
|
95
|
+
<Step title="Join agent machines as the runtime role">
|
|
96
|
+
Follow [Join a machine](#join-a-machine) on each host. If you are deploying PgBouncer in front of PostgreSQL, configure PgBouncer first and join with its endpoint (see [Configure Atomic](/storage/postgres/pgbouncer#configure-atomic)).
|
|
97
|
+
</Step>
|
|
98
|
+
</Steps>
|
|
99
|
+
|
|
100
|
+
If the runtime role lacks a required grant—or tables are behind the running Atomic version—opening fails with `StorageConfigError` (`reason: "missing-privilege"`), naming the exact `GRANT` or `atomic storage migrate` command to run.
|
|
99
101
|
|
|
100
102
|
### After each Atomic upgrade
|
|
101
103
|
|
|
102
|
-
Run `atomic storage migrate` as the owner role
|
|
104
|
+
Run `atomic storage migrate` once as the owner role after upgrading Atomic and before scaling up agents. Because the runtime role cannot run DDL, running `migrate` handles everything that requires table ownership:
|
|
103
105
|
|
|
104
|
-
-
|
|
105
|
-
-
|
|
106
|
-
-
|
|
107
|
-
-
|
|
106
|
+
- **Schema and lazy objects:** creates new tables, lazily initialized tables/functions (fork staging, chat records, the single-round-trip session append function, and Intercom's ended-child queue tables), and shared-history fork upgrades.
|
|
107
|
+
- **Non-blocking index rebuilds:** rebuilds the `snapshot_session_links` index concurrently without blocking writes (with a 6-hour statement timeout for large tables).
|
|
108
|
+
- **Table tuning:** applies `fillfactor`, autovacuum thresholds, search index parameters, unlogged wake-up notices, and `lz4` compression where supported (see [Server tuning](/storage/postgres/tuning)). Each table tuning statement uses a 2-second `lock_timeout` and gracefully skips busy tables rather than failing the migration—re-run later if any table was reported busy.
|
|
109
|
+
- **Search trigram index:** installs `pg_trgm` once allowed on managed providers (see [Managed PostgreSQL services](#managed-postgresql-services)).
|
|
108
110
|
|
|
109
|
-
Running
|
|
111
|
+
Running `atomic storage migrate` on an already up-to-date database is a no-op.
|
|
110
112
|
|
|
111
113
|
### Share one database between teams
|
|
112
114
|
|
|
113
|
-
|
|
115
|
+
Isolate teams or projects either in separate databases or with a table `prefix` (no prefix by default). Pass the same `--prefix` to `atomic storage migrate` and to every `atomic storage join` in that group; hosts with a different prefix cannot see those sessions.
|
|
114
116
|
|
|
115
|
-
On PostgreSQL, a prefix
|
|
117
|
+
On PostgreSQL, a prefix may contain at most **24 lowercase ASCII characters**. Longer prefixes fail with `StoragePrefixError` (`too-long`), and uppercase letters fail with `uppercase`.
|
|
116
118
|
|
|
117
119
|
### Upgrading from tables in `public`
|
|
118
120
|
|
|
119
|
-
Older releases
|
|
121
|
+
Older Atomic releases placed tables in the `public` schema. Atomic continues using them until you migrate them to `atomic`:
|
|
120
122
|
|
|
121
|
-
1. Upgrade Atomic on every machine.
|
|
122
|
-
2. Run `atomic storage migrate` once
|
|
123
|
-
3.
|
|
123
|
+
1. Upgrade Atomic on every machine sharing the database.
|
|
124
|
+
2. Run `atomic storage migrate` once as the owner of the tables in `public` (moves all Atomic tables—and any legacy `wf_*` tables—to `atomic` in one transaction).
|
|
125
|
+
3. Grant runtime privileges on `atomic` as in step 4 of [Set up the database](#set-up-the-database).
|
|
124
126
|
4. Restart every Atomic process that opened the database before the move.
|
|
125
127
|
|
|
126
|
-
|
|
128
|
+
Processes still targeting `public` after the move are refused so data never splits across schemas. If an older process creates a stray table in `public` afterward, the next `atomic storage migrate` names it and stops rather than discarding it.
|
|
127
129
|
|
|
128
130
|
## Join a machine
|
|
129
131
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
Intercom: PostgreSQL postgresql://db.example.com:5432/atomic via @bastani/atomic-storage-postgres
|
|
175
|
-
source: global settings: storage
|
|
176
|
-
adapter: loaded (from /home/me/.atomic/agent/npm/node_modules/@bastani/atomic-storage-postgres/postgres.js)
|
|
177
|
-
connection: ok (postgres postgresql://db.example.com:5432/atomic answered in 11 ms, PostgreSQL 17.12; wake-ups: LISTEN/NOTIFY)
|
|
178
|
-
multi-node: on
|
|
179
|
-
brokers: 0 live in the database
|
|
180
|
-
|
|
181
|
-
Intercom broker: not running (the next session that uses Intercom starts one with the selection above)
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
`multi-node: on` means agents on this machine can message agents on the other machines that joined. A broker starts with the first session that uses Intercom, so right after a restart `brokers` can show `0` and the broker `not running`. Once sessions run on the joined machines, `brokers` counts their brokers.
|
|
185
|
-
|
|
186
|
-
5. **Delete your password file**, `~/atomic-db-password`. `atomic storage join` keeps its own copy.
|
|
187
|
-
|
|
188
|
-
`atomic storage join` takes a `postgres://` or `postgresql://` URL that names the user and never the password. Pass exactly one way to log in:
|
|
189
|
-
|
|
190
|
-
| Option | What Atomic does |
|
|
132
|
+
Run these steps on each machine as the user who runs Atomic:
|
|
133
|
+
|
|
134
|
+
<Steps>
|
|
135
|
+
<Step title="Install the PostgreSQL adapter">
|
|
136
|
+
```bash
|
|
137
|
+
atomic install npm:@bastani/atomic-storage-postgres
|
|
138
|
+
```
|
|
139
|
+
</Step>
|
|
140
|
+
<Step title="Save the runtime password to a private file">
|
|
141
|
+
Reading from stdin keeps the password out of shell history:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
(umask 077; printf 'Runtime password: '; read -rs password; printf '\n'; printf '%s' "$password" > ~/atomic-db-password)
|
|
145
|
+
```
|
|
146
|
+
</Step>
|
|
147
|
+
<Step title="Join the database">
|
|
148
|
+
```bash
|
|
149
|
+
atomic storage join 'postgresql://atomic_runtime@db.example.com:5432/atomic' --password-file ~/atomic-db-password
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Atomic validates the URL, adapter, credentials, and a `SELECT 1` probe (15-second timeout) before writing anything, copies the password to an owner-only `~/.atomic/agent/storage-token.<id>` file (mode `600`), and updates only the top-level `storage` key in `~/.atomic/agent/settings.json`.
|
|
153
|
+
</Step>
|
|
154
|
+
<Step title="Restart Intercom and verify status">
|
|
155
|
+
Restart the local Intercom broker so it adopts the shared database (safe if no broker is running; already-open sessions keep their old store until restarted):
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
atomic intercom restart
|
|
159
|
+
atomic storage status
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
`atomic storage status` exits `0` when both sessions and Intercom connect, reporting `multi-node: on` and `wake-ups: LISTEN/NOTIFY`. The broker starts on demand with the first session that uses Intercom, so `brokers: 0 live` right after a restart is expected.
|
|
163
|
+
</Step>
|
|
164
|
+
<Step title="Delete your temporary password file">
|
|
165
|
+
```bash
|
|
166
|
+
rm ~/atomic-db-password
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
`atomic storage join` already saved its own private copy inside `~/.atomic/agent/`.
|
|
170
|
+
</Step>
|
|
171
|
+
</Steps>
|
|
172
|
+
|
|
173
|
+
`atomic storage join` accepts a `postgres://` or `postgresql://` URL with the username and **never** a password. Supply exactly one credential flag:
|
|
174
|
+
|
|
175
|
+
| Option | Behavior |
|
|
191
176
|
| --- | --- |
|
|
192
|
-
| `--password-file <path>` | Copies the password into
|
|
193
|
-
| `--token-file <path>` |
|
|
194
|
-
| `--auth azure`, `--auth aws`, or `--auth gcp` |
|
|
177
|
+
| `--password-file <path>` | Copies the password into `~/.atomic/agent/storage-token.<id>` (mode `600`). Safe to delete your source file afterward. |
|
|
178
|
+
| `--token-file <path>` | Stores the path and re-reads the file for every new connection—ideal for Vault agents or rotating token sidecars. Strips one trailing newline only. |
|
|
179
|
+
| `--auth azure`, `--auth aws`, or `--auth gcp` | Authenticates with the machine's [cloud identity](#cloud-identities). |
|
|
180
|
+
|
|
181
|
+
<Note>
|
|
182
|
+
`atomic storage join` overwrites any existing top-level `storage` setting without keeping a backup. Save your previous `storage` value first if you need it.
|
|
183
|
+
</Note>
|
|
195
184
|
|
|
196
|
-
|
|
185
|
+
The written `~/.atomic/agent/settings.json` entry looks like this (keep the exact `storage-token.<id>` filename that `atomic storage join` generated on your machine; `storage-token.example` is a placeholder in the examples below):
|
|
197
186
|
|
|
198
187
|
```json
|
|
199
188
|
{
|
|
200
189
|
"storage": {
|
|
201
190
|
"adapter": "@bastani/atomic-storage-postgres",
|
|
202
191
|
"options": { "url": "postgresql://atomic_runtime@db.example.com:5432/atomic" },
|
|
203
|
-
"secrets": { "password": { "file": "agent/storage-token.
|
|
192
|
+
"secrets": { "password": { "file": "agent/storage-token.example" } }
|
|
204
193
|
}
|
|
205
194
|
}
|
|
206
195
|
```
|
|
207
196
|
|
|
208
|
-
`
|
|
209
|
-
|
|
210
|
-
You can write this setting yourself instead, or pass the same object in `ATOMIC_STORAGE` or `--storage`. Give the password in `secrets.password`, as `{ "file": "<path>" }` or `{ "env": "<variable>" }`. Atomic reads it again for every new connection, so a rotated password takes effect without a restart. A password in `options` is ignored, and a missing `secrets.password` fails with `StorageConfigError` and reason `secret-missing`.
|
|
197
|
+
Relative `secrets.password.file` paths resolve against the [storage home](/storage#storage-home) (`~/.atomic`). You can also author this object directly in `settings.json`, `ATOMIC_STORAGE`, or `--storage` using `{ "file": "<path>" }` or `{ "env": "<VAR>" }`. Atomic re-reads `secrets.password` on every new connection, so rotated passwords take effect without restarts. A password placed in `options` is ignored, and missing `secrets.password` fails with `StorageConfigError` (`secret-missing`).
|
|
211
198
|
|
|
212
199
|
### Connection options
|
|
213
200
|
|
|
214
|
-
|
|
201
|
+
Configure these under `options` (defaults suit small deployments; see [Tuning for many concurrent agents](#tuning-for-many-concurrent-agents) for larger fleets):
|
|
215
202
|
|
|
216
203
|
| Option | Default | What it does |
|
|
217
204
|
| --- | --- | --- |
|
|
218
|
-
| `url` | Required |
|
|
219
|
-
| `auth` | `"password"` | `"azure-entra"`, `"aws-iam"`, or `"gcp-iam"`
|
|
220
|
-
| `maxConnections` | `8` |
|
|
221
|
-
| `readerMaxConnections` | `2` |
|
|
222
|
-
| `statementTimeoutMs` | `30000` |
|
|
223
|
-
| `connectTimeoutMs` | `10000` |
|
|
224
|
-
| `idleTimeoutMs` | `300000` | How long
|
|
225
|
-
| `keepAliveIdleMs` | `60000` |
|
|
226
|
-
| `maxPreparedStatements` | `256
|
|
227
|
-
| `listenUrl` | Same as `url` |
|
|
228
|
-
| `schema` | `"atomic"` |
|
|
229
|
-
| `proxy` | From
|
|
230
|
-
|
|
231
|
-
For
|
|
205
|
+
| `url` | Required | `postgres://` or `postgresql://` URL containing the username and no password. |
|
|
206
|
+
| `auth` | `"password"` | `"azure-entra"`, `"aws-iam"`, or `"gcp-iam"` for [cloud identities](#cloud-identities). |
|
|
207
|
+
| `maxConnections` | `8` | Maximum main-pool connections opened by one Atomic process (positive integer). |
|
|
208
|
+
| `readerMaxConnections` | `2` | Maximum dedicated read-only connections per process (capped at `maxConnections`; `0` disables the read pool). |
|
|
209
|
+
| `statementTimeoutMs` | `30000` | Server-side statement cancellation timeout (ms). Atomic drops an unresponsive connection 5 seconds past this limit. |
|
|
210
|
+
| `connectTimeoutMs` | `10000` | Timeout for establishing a connection or waiting for a free pool slot (ms). |
|
|
211
|
+
| `idleTimeoutMs` | `300000` | How long the last idle connection in a pool stays open (ms). Burst connections close after 10 seconds idle. |
|
|
212
|
+
| `keepAliveIdleMs` | `60000` | Idle period before sending TCP keepalive probes (ms). |
|
|
213
|
+
| `maxPreparedStatements` | `256` (or `0` behind unsupported poolers) | Prepared statements cached per connection (`0` disables). Auto-detected behind PgBouncer; see [Prepared statements](/storage/postgres/pgbouncer#how-atomic-works-with-pgbouncer). |
|
|
214
|
+
| `listenUrl` | Same as `url` | Direct PostgreSQL endpoint for Intercom [wake-ups](#wake-ups) when `url` points at a transaction pooler. |
|
|
215
|
+
| `schema` | `"atomic"` | Schema for Atomic's tables (lowercase letters, digits, `_`, starting with letter/`_`, max 63 chars). To migrate a custom schema, put it in `storage` and run `atomic storage migrate` without `--db`. |
|
|
216
|
+
| `proxy` | From env | Explicit `http://` or `https://` proxy URL, or `"none"` to bypass proxy variables. See [Through an HTTP proxy](#through-an-http-proxy). |
|
|
217
|
+
|
|
218
|
+
For SDK apps using `openPostgresDatabase()`, see [`@bastani/atomic-storage-postgres`](/libraries/storage-postgres) and [SDK session storage](/sdk/storage).
|
|
232
219
|
|
|
233
220
|
## TLS
|
|
234
221
|
|
|
235
|
-
Atomic encrypts every
|
|
222
|
+
Atomic encrypts every remote connection and verifies both the server's certificate and hostname (`sslmode=verify-full`) by default. Connections to `localhost`, loopback addresses, and Unix sockets skip TLS unless `sslmode` is specified in the URL. When the URL omits a host, Atomic reads `PGHOST`.
|
|
236
223
|
|
|
237
|
-
|
|
224
|
+
Override TLS behavior with a lowercase `sslmode` query parameter in `url`:
|
|
238
225
|
|
|
239
|
-
| `sslmode` | Encrypts |
|
|
226
|
+
| `sslmode` | Encrypts | Verifies certificate | Verifies hostname |
|
|
240
227
|
| --- | --- | --- | --- |
|
|
241
|
-
| `verify-full
|
|
228
|
+
| `verify-full` (default) | Yes | Yes | Yes |
|
|
242
229
|
| `verify-ca` | Yes | Yes | No |
|
|
243
230
|
| `require` with `sslrootcert` | Yes | Yes | No |
|
|
244
231
|
| `require` without `sslrootcert` | Yes | Yes | Yes |
|
|
245
232
|
| `prefer` or `allow` | Yes | No | No |
|
|
246
233
|
| `disable` | No | No | No |
|
|
247
234
|
|
|
248
|
-
`require` without `sslrootcert`
|
|
235
|
+
Note that `require` without `sslrootcert` verifies more strictly than `psql`. Unknown `sslmode` values or uppercase TLS parameter names fail with `StorageConfigError`.
|
|
249
236
|
|
|
250
|
-
|
|
237
|
+
**Certificate authorities (`sslrootcert`):**
|
|
251
238
|
|
|
252
|
-
- **Self-hosted PostgreSQL
|
|
253
|
-
- **Azure
|
|
254
|
-
- **Supabase
|
|
255
|
-
- **Amazon RDS
|
|
256
|
-
- **Google Cloud SQL
|
|
239
|
+
- **Self-hosted PostgreSQL:** Enable `ssl = on`, `ssl_cert_file`, and `ssl_key_file` in `postgresql.conf` with a certificate matching the hostname in `url`. For a private CA, append `?sslrootcert=/path/to/root.crt`. Default distro self-signed certificates (like Debian's `snakeoil`) fail default verification.
|
|
240
|
+
- **Azure Flexible Server, Azure HorizonDB, and Neon:** Trusted by Node.js's built-in CA store; no `sslrootcert` needed.
|
|
241
|
+
- **Supabase:** Download the project CA from Project Settings → Database → SSL Configuration and pass `?sslrootcert=/path/to/supabase-ca.pem`.
|
|
242
|
+
- **Amazon RDS / Aurora:** Download `https://truststore.pki.rds.amazonaws.com/<region>/<region>-bundle.pem` and pass `?sslrootcert=/path/to/bundle.pem`.
|
|
243
|
+
- **Google Cloud SQL:** Export the server CA with `gcloud sql instances describe <instance> --format='value(serverCaCert.cert)'`. Over private IP, pass `?sslmode=verify-ca&sslrootcert=/path/to/server-ca.pem` (the certificate does not list private IPs).
|
|
257
244
|
|
|
258
245
|
## Through an HTTP proxy
|
|
259
246
|
|
|
260
|
-
|
|
247
|
+
When outbound network traffic must traverse an HTTP proxy, Atomic tunnels PostgreSQL connections using HTTP `CONNECT`. Allow `<database-host>:5432` (or your server port) on the proxy.
|
|
261
248
|
|
|
262
|
-
- **
|
|
263
|
-
- **
|
|
264
|
-
- **
|
|
265
|
-
- **
|
|
249
|
+
- **Proxy selection:** Reads `HTTPS_PROXY` / `https_proxy`, then `ALL_PROXY` (for `http://` or `https://`), then `HTTP_PROXY`. Embedded proxy credentials are sent to the proxy and redacted from logs and errors.
|
|
250
|
+
- **Bypass rules:** `NO_PROXY` / `no_proxy` accepts hostnames, `.example.com`, `*.example.com`, `host:port`, or `*`. `localhost`, loopback addresses, and Unix sockets always connect directly.
|
|
251
|
+
- **Per-store override:** Set `options.proxy` to a proxy URL for one store, or `"none"` to ignore environment proxy variables.
|
|
252
|
+
- **End-to-end TLS:** TLS runs inside the tunnel so the proxy sees encrypted bytes only. With `verify-full`, the certificate must match the database hostname; `verify-ca` defends against proxy interception only when `sslrootcert` trusts solely your database CA.
|
|
266
253
|
|
|
267
|
-
|
|
254
|
+
A `403` or `407` proxy rejection fails immediately with `StorageUnavailableError`. Connection drops or `502`/`503` responses retry like an unreachable server and log a warning naming the proxy.
|
|
268
255
|
|
|
269
256
|
## Connection budget
|
|
270
257
|
|
|
271
|
-
Connections are
|
|
258
|
+
Connections are pooled **per Atomic process**. Each of the following counts as one process:
|
|
272
259
|
|
|
273
|
-
-
|
|
274
|
-
-
|
|
275
|
-
-
|
|
260
|
+
- every interactive `atomic` or `atomic -p` invocation;
|
|
261
|
+
- every `atomic --mode rpc` subprocess;
|
|
262
|
+
- each Intercom broker (one per agent directory, typically one per host or container).
|
|
276
263
|
|
|
277
|
-
Subagents run inside
|
|
264
|
+
Subagents run inside their parent process and share its pools without opening extra connections.
|
|
278
265
|
|
|
279
|
-
|
|
266
|
+
Within a process, sessions, subagents, search, and Intercom share one pool per identical database configuration:
|
|
280
267
|
|
|
281
|
-
|
|
|
268
|
+
| Pool | Max connections | `application_name` in `pg_stat_activity` |
|
|
282
269
|
| --- | --- | --- |
|
|
283
|
-
| Main pool |
|
|
284
|
-
| Read pool |
|
|
285
|
-
| Wake-up
|
|
286
|
-
|
|
287
|
-
So a process opens at most `maxConnections` + `readerMaxConnections` connections, 10 with the defaults, and a process that listens, such as an Intercom broker, 1 more: 11.
|
|
270
|
+
| Main pool | `maxConnections` (default `8`) | `atomic` |
|
|
271
|
+
| Read pool | `readerMaxConnections` (default `2`; reads only) | `atomic-reader` |
|
|
272
|
+
| Wake-up listener | `1` (listening processes such as Intercom brokers only) | `atomic-listen` |
|
|
288
273
|
|
|
289
|
-
|
|
274
|
+
At defaults, one agent process opens at most **10** connections, and an Intercom broker opens at most **11**.
|
|
290
275
|
|
|
291
|
-
|
|
276
|
+
Connections open lazily and scale back down automatically: burst connections close after 10 seconds idle, while the final connection in each pool stays warm for `idleTimeoutMs` (5 minutes by default). Open connections never prevent a process from exiting.
|
|
292
277
|
|
|
293
|
-
- **
|
|
294
|
-
- **
|
|
295
|
-
- **More processes than
|
|
278
|
+
- **Small team / interactive use:** keep the defaults.
|
|
279
|
+
- **Large fleet with idle periods:** size `maxConnections` via [Tuning for many concurrent agents](#tuning-for-many-concurrent-agents) and lower `idleTimeoutMs` (for example `10000`–`30000`) so idle processes release connections faster.
|
|
280
|
+
- **More processes than `max_connections` allows:** deploy [PgBouncer](/storage/postgres/pgbouncer) in transaction mode and point `listenUrl` directly at PostgreSQL.
|
|
296
281
|
|
|
297
282
|
## Connection poolers
|
|
298
283
|
|
|
299
|
-
|
|
284
|
+
Atomic supports connection poolers in **transaction mode** or **session mode** (never statement mode), including self-hosted PgBouncer, Azure Flexible Server's built-in PgBouncer (port 6432), Supabase Supavisor (port 6543), and Neon's `-pooler` endpoint.
|
|
300
285
|
|
|
301
|
-
|
|
286
|
+
Transaction poolers cannot forward PostgreSQL `LISTEN`/`NOTIFY` notifications, so set `listenUrl` to PostgreSQL's direct endpoint (for example port 5432 on Azure, or Neon's non-`-pooler` host). Without `listenUrl`, Intercom still delivers messages by polling every 0.5 seconds (see [Wake-ups](#wake-ups)).
|
|
302
287
|
|
|
303
|
-
|
|
288
|
+
For a complete TLS + SCRAM PgBouncer setup, see [PostgreSQL with PgBouncer](/storage/postgres/pgbouncer).
|
|
304
289
|
|
|
305
290
|
## Wake-ups
|
|
306
291
|
|
|
307
|
-
When
|
|
292
|
+
When a machine sends a cross-host Intercom message, the receiving broker learns about it immediately through PostgreSQL `LISTEN`/`NOTIFY`. Each listening process (such as an Intercom broker) holds one dedicated `atomic-listen` connection per database.
|
|
308
293
|
|
|
309
|
-
|
|
294
|
+
Atomic backs up real-time notifications with two independent polling safety nets:
|
|
310
295
|
|
|
311
|
-
`
|
|
296
|
+
- **Wake-up hint poll (`intercom_wakeups`):** While `LISTEN/NOTIFY` is live, each broker polls wake-up hints every **5 seconds** to catch any missed notification. If the `LISTEN` connection drops—or `url` points at a transaction pooler without `listenUrl`—brokers poll wake-up hints every **0.5 seconds** (500 ms) instead. Atomic retries reconnecting a dropped `LISTEN` connection every 30 seconds (behind a transaction pooler without `listenUrl`, it stays in polling mode until restart).
|
|
297
|
+
- **Backup outbox scan (`intercom_outbox`):** Independently of wake-up hints, every broker scans the durable outbox table directly every **30 seconds**. Even if a server crash or failover empties the unlogged `intercom_wakeups` table, every message still arrives within 30 seconds (see [Intercom's wake-up notices](/storage/postgres/tuning#intercoms-wake-up-notices)).
|
|
298
|
+
|
|
299
|
+
Check wake-up health with `atomic storage status`:
|
|
312
300
|
|
|
313
301
|
| Status line | Meaning |
|
|
314
302
|
| --- | --- |
|
|
315
|
-
| `wake-ups: LISTEN/NOTIFY` |
|
|
316
|
-
| `wake-ups: connecting` |
|
|
317
|
-
| `wake-ups: polling only, notifications do not pass the URL's transaction pooler (set listenUrl to a direct endpoint)` | `url`
|
|
318
|
-
| `wake-ups: polling only, the listen connection failed` |
|
|
303
|
+
| `wake-ups: LISTEN/NOTIFY` | Instant notifications are active. |
|
|
304
|
+
| `wake-ups: connecting` | Listener connection is opening. |
|
|
305
|
+
| `wake-ups: polling only, notifications do not pass the URL's transaction pooler (set listenUrl to a direct endpoint)` | `url` hits a transaction pooler; set `listenUrl` to the direct server endpoint. |
|
|
306
|
+
| `wake-ups: polling only, the listen connection failed` | Listener failed to connect or authenticate; check `listenUrl` and `max_connections`. |
|
|
307
|
+
|
|
308
|
+
## Managed PostgreSQL services
|
|
309
|
+
|
|
310
|
+
All major managed PostgreSQL services work with the roles in [Set up the database](#set-up-the-database). Provider-specific notes:
|
|
311
|
+
|
|
312
|
+
### Azure
|
|
313
|
+
|
|
314
|
+
- **Azure Database for PostgreSQL Flexible Server:** Connect to `<server>.postgres.database.azure.com:5432` (TLS trusted automatically). Run role setup as a member of `azure_pg_admin` (if using `schema: "public"`, also run `GRANT CREATE ON SCHEMA public TO atomic_owner;`). On General Purpose / Memory Optimized tiers, enable built-in PgBouncer (`pgbouncer.enabled`, port 6432) and point `listenUrl` at port 5432. Allow `PG_TRGM` in `azure.extensions` and run `atomic storage migrate` for indexed history search. Note smaller tiers like Burstable B1ms allow only 50 connections (with 15 reserved for admins).
|
|
315
|
+
- **Azure HorizonDB (preview, PostgreSQL 17):** Connect to the read/write endpoint (`<cluster>.rw.<id>.<region>.horizondb.azure.com:5432`); read-only endpoints are unsupported because Atomic writes on open. Wake-ups work on the read/write endpoint. Allow `pg_trgm` in the compute pool's parameter group, then run `atomic storage migrate`.
|
|
316
|
+
- Both support Microsoft Entra ID via `--auth azure`.
|
|
319
317
|
|
|
320
|
-
|
|
318
|
+
### Amazon RDS and Aurora
|
|
321
319
|
|
|
322
|
-
|
|
320
|
+
- Connect to the writer endpoint (never a read-only replica) and pass the regional CA bundle via `?sslrootcert=/path/to/<region>-bundle.pem` (see [TLS](#tls)).
|
|
321
|
+
- If using Amazon RDS Proxy, point `listenUrl` at the DB instance endpoint and set `maxPreparedStatements: 0` (RDS Proxy listens on port 5432 and does not preserve prepared statements or `LISTEN`).
|
|
322
|
+
- Supports IAM authentication via `--auth aws`.
|
|
323
323
|
|
|
324
|
-
|
|
325
|
-
- On General Purpose and Memory Optimized tiers, you can turn on the built-in PgBouncer with the `pgbouncer.enabled` server parameter. It listens on port 6432. Point `url` at port 6432 and `listenUrl` at port 5432.
|
|
326
|
-
- Add `PG_TRGM` to the `azure.extensions` server parameter, then run `atomic storage migrate`, so Atomic can index session history search. Without it, search still works but reads sessions one page at a time, and `atomic storage migrate` tells you to run it again once the extension is allowed.
|
|
327
|
-
- Watch the connection limit. A Burstable B1ms server allows 50 connections and keeps 15 of them for administrators. With the defaults, one Atomic process can open 10, and an Intercom broker 11. Lower `maxConnections`, use PgBouncer, or pick a larger server. See [Connection budget](#connection-budget).
|
|
328
|
-
- Allow your machines' addresses in the firewall rules, or use private access.
|
|
324
|
+
### Google Cloud SQL
|
|
329
325
|
|
|
330
|
-
|
|
326
|
+
- Run initial role creation as `postgres` or a member of `cloudsqlsuperuser`, and pass the exported server CA via `sslrootcert` (use `sslmode=verify-ca` over private IP; see [TLS](#tls)).
|
|
327
|
+
- Supports IAM authentication via `--auth gcp`.
|
|
331
328
|
|
|
332
|
-
|
|
333
|
-
- Add `pg_trgm` to `azure.extensions` in the compute pool's parameter group, then run `atomic storage migrate`.
|
|
334
|
-
- Allow your machines' addresses in the firewall rules, or connect over a private endpoint.
|
|
329
|
+
### Neon and Supabase
|
|
335
330
|
|
|
336
|
-
|
|
331
|
+
- **Neon:** Built-in TLS CA is trusted automatically. For pooled connections, point `url` at the `-pooler` host and `listenUrl` at the direct host without `-pooler`.
|
|
332
|
+
- **Supabase:** Download the project CA certificate for `sslrootcert` (see [TLS](#tls)). For Supavisor transaction pooling, point `url` at port 6543 and `listenUrl` at port 5432; leave `maxPreparedStatements` unset so Atomic keeps prepared statements off behind Supavisor.
|
|
337
333
|
|
|
338
334
|
## Cloud identities
|
|
339
335
|
|
|
340
|
-
|
|
336
|
+
Machines on Azure, AWS, or Google Cloud can authenticate using short-lived cloud IAM tokens instead of static passwords. Tokens are requested per new connection and kept in memory only. Install the provider's library once per machine:
|
|
341
337
|
|
|
342
|
-
| `--auth` | `options.auth` | Install |
|
|
338
|
+
| `--auth` | `options.auth` | Install command | Identity source |
|
|
343
339
|
| --- | --- | --- | --- |
|
|
344
|
-
| `azure`
|
|
345
|
-
| `aws`
|
|
346
|
-
| `gcp`
|
|
340
|
+
| `azure` / `azure-entra` | `"azure-entra"` | `atomic install npm:@azure/identity` | `AZURE_*` env vars, AKS workload identity, VM/App Service/Container App managed identity (`AZURE_CLIENT_ID`), or `az login` |
|
|
341
|
+
| `aws` / `aws-iam` | `"aws-iam"` | `atomic install npm:@aws-sdk/rds-signer` | Standard AWS credential chain (`AWS_*`, profiles, IRSA, instance profile) |
|
|
342
|
+
| `gcp` / `gcp-iam` | `"gcp-iam"` | `atomic install npm:google-auth-library` | Application Default Credentials (`GOOGLE_APPLICATION_CREDENTIALS`, GCE/GKE/Cloud Run metadata, or `gcloud auth application-default login`) |
|
|
347
343
|
|
|
348
|
-
|
|
344
|
+
`atomic install` places these libraries in `~/.atomic/agent/npm`, where `@bastani/atomic-storage-postgres` discovers them. Missing libraries or unavailable credentials fail immediately with `StorageConfigError` (`auth-unavailable`). Cloud IAM tokens require TLS, so keep the default `sslmode`.
|
|
349
345
|
|
|
350
|
-
|
|
346
|
+
Map the cloud identity to a PostgreSQL role and grant it the runtime privileges from [Set up the database](#set-up-the-database):
|
|
351
347
|
|
|
352
|
-
- **Azure
|
|
353
|
-
- **AWS
|
|
354
|
-
- **Google Cloud
|
|
348
|
+
- **Azure:** Enable Microsoft Entra authentication, connect to `postgres` as the Entra admin, run `SELECT * FROM pgaadauth_create_principal('<identity name>', false, false);`, grant `CONNECT` on the `atomic` database, and use `<identity name>` as the URL user.
|
|
349
|
+
- **AWS:** Enable IAM database authentication, run `CREATE USER atomic; GRANT rds_iam TO atomic;`, and grant the IAM identity `rds-db:connect` on `arn:aws:rds-db:<region>:<account>:dbuser:<DbiResourceId>/atomic`.
|
|
350
|
+
- **Google Cloud:** Enable `cloudsql.iam_authentication=on`, add the service account as an IAM database user with `roles/cloudsql.instanceUser`, and use the service account email without `.gserviceaccount.com` as the URL user (Compute Engine VMs need the `cloud-platform` scope).
|
|
355
351
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
`atomic install` puts these libraries in `~/.atomic/agent/npm`, where the PostgreSQL adapter looks for them.
|
|
352
|
+
See [`@bastani/atomic-storage-postgres`](/libraries/storage-postgres) for full SDK options.
|
|
359
353
|
|
|
360
354
|
## Tuning for many concurrent agents
|
|
361
355
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
This section covers Atomic's settings. For the server side, such as memory, monitoring, and the busiest tables, see [Server tuning](/storage/postgres/tuning).
|
|
356
|
+
Write parallelism scales with each process's connection pool: writes to different sessions run concurrently on separate connections, while writes to the same session serialize. This section covers client-side Atomic settings; for server memory, autovacuum, and monitoring, see [Server tuning](/storage/postgres/tuning).
|
|
365
357
|
|
|
366
|
-
Every Atomic process
|
|
358
|
+
Every Atomic process across all hosts shares PostgreSQL's `max_connections`. Give each process as many connections as the server can safely spare, and no more.
|
|
367
359
|
|
|
368
360
|
### Count the connections Atomic needs
|
|
369
361
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
- **An agent process**, including each `atomic --mode rpc` child: `maxConnections` plus `readerMaxConnections`.
|
|
373
|
-
- **An Intercom broker**: `maxConnections` plus `readerMaxConnections`, plus 1 for [wake-ups](#wake-ups).
|
|
362
|
+
Plan for each process's peak connection count (from [Connection budget](#connection-budget)):
|
|
374
363
|
|
|
375
|
-
|
|
364
|
+
- **Agent process** (including each `atomic --mode rpc` child): `maxConnections + readerMaxConnections`
|
|
365
|
+
- **Intercom broker:** `maxConnections + readerMaxConnections + 1` (for wake-ups)
|
|
376
366
|
|
|
377
|
-
|
|
367
|
+
Check available slots on the server as an administrator:
|
|
378
368
|
|
|
379
369
|
```sql
|
|
380
370
|
SHOW max_connections;
|
|
@@ -384,24 +374,24 @@ SELECT count(*) FROM pg_stat_activity
|
|
|
384
374
|
WHERE backend_type = 'client backend' AND application_name NOT LIKE 'atomic%';
|
|
385
375
|
```
|
|
386
376
|
|
|
387
|
-
|
|
377
|
+
Calculate `maxConnections`:
|
|
388
378
|
|
|
389
|
-
1.
|
|
390
|
-
2. Count *P
|
|
391
|
-
3. Each process
|
|
392
|
-
4. Set `maxConnections`
|
|
379
|
+
1. Compute *available* = `max_connections` − reserved slots − non-Atomic client connections.
|
|
380
|
+
2. Count *P* (total Atomic processes across all hosts) and *B* (Intercom brokers—usually one per host or container).
|
|
381
|
+
3. Each process gets `floor((available − B) / P)` connections.
|
|
382
|
+
4. Set `maxConnections` = that budget minus `readerMaxConnections`.
|
|
393
383
|
|
|
394
|
-
If step 4
|
|
384
|
+
If step 4 produces `maxConnections` below `2`, put [PgBouncer](/storage/postgres/pgbouncer) in front of the server (see the second example below).
|
|
395
385
|
|
|
396
|
-
A
|
|
386
|
+
A default server (`max_connections = 100`, 3 superuser slots) fits about 8 processes at default settings (10 per agent, 11 per broker). For example, 20 agents across 4 machines (4 brokers) can open up to `20 × 10 + 4 × 11 = 244` connections—requiring higher `max_connections`, lower `maxConnections`, or PgBouncer.
|
|
397
387
|
|
|
398
388
|
### Example: 24 processes on a large server
|
|
399
389
|
|
|
400
|
-
Four machines each run
|
|
390
|
+
Four machines each run 5 agent processes and 1 Intercom broker (*P* = 24, *B* = 4). The server has `max_connections = 500`, 3 superuser slots, 0 other reserved slots, and 20 non-Atomic connections:
|
|
401
391
|
|
|
402
|
-
- *available*
|
|
403
|
-
-
|
|
404
|
-
- With
|
|
392
|
+
- *available* = 500 − 3 − 0 − 20 = 477
|
|
393
|
+
- Per-process budget = `floor((477 − 4) / 24)` = 19
|
|
394
|
+
- With default `readerMaxConnections: 2`, set `maxConnections: 17`.
|
|
405
395
|
|
|
406
396
|
In `~/.atomic/agent/settings.json` on each machine:
|
|
407
397
|
|
|
@@ -414,12 +404,12 @@ In `~/.atomic/agent/settings.json` on each machine:
|
|
|
414
404
|
"maxConnections": 17,
|
|
415
405
|
"readerMaxConnections": 2
|
|
416
406
|
},
|
|
417
|
-
"secrets": { "password": { "file": "agent/storage-token.
|
|
407
|
+
"secrets": { "password": { "file": "agent/storage-token.example" } }
|
|
418
408
|
}
|
|
419
409
|
}
|
|
420
410
|
```
|
|
421
411
|
|
|
422
|
-
|
|
412
|
+
Equivalent SDK configuration:
|
|
423
413
|
|
|
424
414
|
```typescript
|
|
425
415
|
import { openPostgresDatabase } from "@bastani/atomic-storage-postgres";
|
|
@@ -434,13 +424,13 @@ const database = await openPostgresDatabase({
|
|
|
434
424
|
|
|
435
425
|
### Example: 150 machines on a smaller server
|
|
436
426
|
|
|
437
|
-
Here, 150 CI runners each run
|
|
427
|
+
Here, 150 CI runners each run 1 agent process and 1 Intercom broker (*P* = 300, *B* = 150) against a server with `max_connections = 300`, 3 superuser slots, and 10 other clients (*available* = 287).
|
|
438
428
|
|
|
439
|
-
Even
|
|
429
|
+
Even with `maxConnections: 1` and `readerMaxConnections: 0`, 300 processes need `300 + 150 = 450` connections—more than 287. Route traffic through [PgBouncer](/storage/postgres/pgbouncer) in transaction mode on port 6432:
|
|
440
430
|
|
|
441
|
-
- **Point `url` at PgBouncer
|
|
442
|
-
- **Point `listenUrl` at
|
|
443
|
-
- **
|
|
431
|
+
- **Point `url` at PgBouncer** and keep `maxConnections: 8`. Set PgBouncer's `max_client_conn` above `P × (maxConnections + readerMaxConnections)` (`300 × 10 = 3000`).
|
|
432
|
+
- **Point `listenUrl` directly at PostgreSQL** (optional). With `listenUrl`, each broker holds 1 direct connection for instant wake-ups and polls hints every 5 seconds; without it, brokers poll every 0.5 seconds.
|
|
433
|
+
- **Cap PgBouncer's server pool** within remaining capacity (`287 − 150 = 137` with `listenUrl`, or `287` without). A smaller pool (such as 80 + 5 reserve in the [PgBouncer guide](/storage/postgres/pgbouncer#choose-the-pool-sizes)) often outperforms a larger one.
|
|
444
434
|
|
|
445
435
|
```json
|
|
446
436
|
{
|
|
@@ -451,12 +441,12 @@ Even at the smallest settings, `maxConnections: 1` and `readerMaxConnections: 0`
|
|
|
451
441
|
"listenUrl": "postgresql://atomic_runtime@db.example.com:5432/atomic",
|
|
452
442
|
"maxConnections": 8
|
|
453
443
|
},
|
|
454
|
-
"secrets": { "password": { "file": "agent/storage-token.
|
|
444
|
+
"secrets": { "password": { "file": "agent/storage-token.example" } }
|
|
455
445
|
}
|
|
456
446
|
}
|
|
457
447
|
```
|
|
458
448
|
|
|
459
|
-
|
|
449
|
+
Equivalent SDK configuration:
|
|
460
450
|
|
|
461
451
|
```typescript
|
|
462
452
|
const database = await openPostgresDatabase({
|
|
@@ -467,24 +457,22 @@ const database = await openPostgresDatabase({
|
|
|
467
457
|
});
|
|
468
458
|
```
|
|
469
459
|
|
|
470
|
-
The [PgBouncer guide](/storage/postgres/pgbouncer) has a complete PgBouncer configuration, the PostgreSQL and Atomic settings that go with it, and how to check that it works.
|
|
471
|
-
|
|
472
460
|
### Other settings
|
|
473
461
|
|
|
474
|
-
|
|
462
|
+
Tune these under `options` (all timeouts are integers in milliseconds):
|
|
475
463
|
|
|
476
|
-
- **
|
|
477
|
-
- **`idleTimeoutMs`** (default `300000
|
|
478
|
-
- **`statementTimeoutMs`** (default `30000`)
|
|
479
|
-
- **`connectTimeoutMs`** (default `10000`)
|
|
480
|
-
- **`keepAliveIdleMs`** (default `60000`)
|
|
481
|
-
- **`maxPreparedStatements`** (default `256`, or `0` behind
|
|
464
|
+
- **Colocate database and agents.** Every save waits for at least one network round trip—run PostgreSQL in the same region as your agents, and run `atomic storage migrate` after upgrades so saves use the single-round-trip append path.
|
|
465
|
+
- **`idleTimeoutMs`** (default `300000`): lower (for example `30000`) when idle processes hold connections on a busy server.
|
|
466
|
+
- **`statementTimeoutMs`** (default `30000`): raise only if legitimate queries hit `StorageTransientError` (`transaction-timeout`).
|
|
467
|
+
- **`connectTimeoutMs`** (default `10000`): raise for high-latency or slow-accepting servers.
|
|
468
|
+
- **`keepAliveIdleMs`** (default `60000`): lower if connections fail with `connection-lost` after idle periods (NAT, firewall, or load balancer dropping idle TCP sockets).
|
|
469
|
+
- **`maxPreparedStatements`** (default `256`, or `0` behind unsupported poolers): lower if server per-connection memory is tight. Atomic auto-detects poolers on ports `6432` and `6543`; behind a pooler on another port, set `listenUrl` or `maxPreparedStatements: 0`. See [Prepared statements](/storage/postgres/pgbouncer#how-atomic-works-with-pgbouncer).
|
|
482
470
|
|
|
483
471
|
### Check the effect
|
|
484
472
|
|
|
485
|
-
Run these as an administrator
|
|
473
|
+
Run these queries as an administrator (replace `atomic` with your database name):
|
|
486
474
|
|
|
487
|
-
|
|
475
|
+
Connections by Atomic pool and state:
|
|
488
476
|
|
|
489
477
|
```sql
|
|
490
478
|
SELECT application_name, state, count(*)
|
|
@@ -494,7 +482,7 @@ GROUP BY 1, 2
|
|
|
494
482
|
ORDER BY 3 DESC;
|
|
495
483
|
```
|
|
496
484
|
|
|
497
|
-
What
|
|
485
|
+
What active connections are waiting on:
|
|
498
486
|
|
|
499
487
|
```sql
|
|
500
488
|
SELECT wait_event_type, wait_event, count(*)
|
|
@@ -504,7 +492,7 @@ GROUP BY 1, 2
|
|
|
504
492
|
ORDER BY 3 DESC;
|
|
505
493
|
```
|
|
506
494
|
|
|
507
|
-
|
|
495
|
+
Total client connections vs. `max_connections`:
|
|
508
496
|
|
|
509
497
|
```sql
|
|
510
498
|
SELECT count(*) AS used, current_setting('max_connections')::int AS max
|
|
@@ -512,45 +500,41 @@ FROM pg_stat_activity
|
|
|
512
500
|
WHERE backend_type = 'client backend';
|
|
513
501
|
```
|
|
514
502
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
| You see | It means | Change |
|
|
503
|
+
| Symptom | Cause | Action |
|
|
518
504
|
| --- | --- | --- |
|
|
519
|
-
| `sorry, too many clients already`, `remaining connection slots are reserved
|
|
520
|
-
| `timeout exceeded when trying to connect` |
|
|
521
|
-
| `the call was queued behind an earlier call that ran 60 seconds without settling
|
|
522
|
-
| Many connections
|
|
523
|
-
|
|
|
524
|
-
| `wake-ups: polling only, the listen connection failed`
|
|
505
|
+
| `sorry, too many clients already`, `remaining connection slots are reserved…`, or `too many connections for role "<role>"` | Processes exceeded server or role connection limits. | Lower `maxConnections`/`readerMaxConnections`, raise `max_connections` or role `CONNECTION LIMIT`, or deploy [PgBouncer](/storage/postgres/pgbouncer). |
|
|
506
|
+
| `timeout exceeded when trying to connect` | All connections in a process's pool stayed busy for `connectTimeoutMs`. | Raise `maxConnections` if server capacity allows, or raise `connectTimeoutMs`. |
|
|
507
|
+
| `the call was queued behind an earlier call that ran 60 seconds without settling…` | An earlier query stalled for 60s (lock wait or overloaded server); the queued call failed without writing. | Inspect `wait_event_type` on active sessions; adding connections will not resolve lock contention. |
|
|
508
|
+
| Many connections waiting on `wait_event_type = 'Lock'` | Multiple agents writing to the same session simultaneously. | Spread concurrent agents across distinct sessions. |
|
|
509
|
+
| Mostly `idle` `atomic` connections near server limit | Idle processes holding warm pool slots. | Lower `idleTimeoutMs`. |
|
|
510
|
+
| `wake-ups: polling only, the listen connection failed` | Broker could not open its `atomic-listen` connection (often out of slots). | Recount connections above and check `listenUrl`. |
|
|
525
511
|
|
|
526
|
-
|
|
512
|
+
The first two rows surface as `StorageTransientError` (`connection-refused`) with the quoted message as `cause`; the third surfaces as `StorageUnavailableError`.
|
|
527
513
|
|
|
528
514
|
## Troubleshooting
|
|
529
515
|
|
|
530
|
-
Errors from `atomic storage join`, `atomic storage migrate`, and opening the database, with what to do:
|
|
531
|
-
|
|
532
516
|
| Error | Fix |
|
|
533
517
|
| --- | --- |
|
|
534
|
-
| `credential-in-url` |
|
|
535
|
-
| `libsql-removed` |
|
|
536
|
-
| `unsupported-auth` |
|
|
537
|
-
| `adapter-not-installed` | Run `atomic install npm:@bastani/atomic-storage-postgres` as the user
|
|
538
|
-
| `auth-unavailable` | Install the cloud library the error
|
|
539
|
-
| `missing-privilege
|
|
540
|
-
| `This database was upgraded since this process started` | `atomic storage migrate` moved
|
|
541
|
-
|
|
|
542
|
-
| `StorageUnavailableError` on open |
|
|
543
|
-
| `self-signed certificate in certificate chain`
|
|
544
|
-
| `INVALID_PURPOSE` |
|
|
545
|
-
| `PATH_LENGTH_EXCEEDED` |
|
|
546
|
-
| `UNSPECIFIED`
|
|
547
|
-
|
|
|
548
|
-
|
|
|
549
|
-
| `unsupported-proxy` | Use an `http://` or `https://` proxy
|
|
550
|
-
| `StorageTransientError`
|
|
551
|
-
| `sorry, too many clients already
|
|
552
|
-
| `timeout exceeded when trying to connect` |
|
|
553
|
-
| `prepared statement "atomic_…" does not exist`
|
|
554
|
-
| `StorageTransientError`
|
|
555
|
-
| `wake-ups: polling only` in `atomic storage status` | Messages still arrive
|
|
556
|
-
| `StorageTransientError`
|
|
518
|
+
| `credential-in-url` | Strip the password from `url` and pass `--password-file` or `--token-file`. |
|
|
519
|
+
| `libsql-removed` | Legacy libSQL URL or removed `atomic team join` command; use `postgres://` with `atomic storage join`, or see [Moving off libSQL](/storage#moving-off-libsql). |
|
|
520
|
+
| `unsupported-auth` | Use `azure`, `aws`, or `gcp` (or `azure-entra`, `aws-iam`, `gcp-iam`). |
|
|
521
|
+
| `adapter-not-installed` | Run `atomic install npm:@bastani/atomic-storage-postgres` as the Atomic user. |
|
|
522
|
+
| `auth-unavailable` | Install the cloud SDK library named in the error and confirm the host has a valid cloud identity (not retried). |
|
|
523
|
+
| `missing-privilege` (PG `42501` or `3F000`) | Run the named `GRANT` (see [Set up the database](#set-up-the-database)) or run `atomic storage migrate` as the owner role. |
|
|
524
|
+
| `This database was upgraded since this process started` | `atomic storage migrate` moved tables from `public` to `atomic` while this process was open; restart the process. |
|
|
525
|
+
| Password/token refused (PG `28P01`, or `28000` on Azure) | Check username, token expiry, or token format. On Azure, use `--auth azure` or request a token for `https://ossrdbms-aad.database.windows.net` (`az account get-access-token --resource-type oss-rdbms`). |
|
|
526
|
+
| `StorageUnavailableError` on open | Invalid credentials (`28P01`/`28000`), missing database (`3D000`), or server older than PostgreSQL 16. |
|
|
527
|
+
| `self-signed certificate in certificate chain` / `unable to get local issuer certificate` | Add `?sslrootcert=/path/to/root.crt` (see [TLS](#tls)). |
|
|
528
|
+
| `INVALID_PURPOSE` | Certificate in `sslrootcert` is not a CA (`basicConstraints=CA:TRUE`) or is client-only; supply the signing CA certificate. |
|
|
529
|
+
| `PATH_LENGTH_EXCEEDED` | Certificate chain exceeds the root CA's path length constraint; reissue or sign directly with the root CA. |
|
|
530
|
+
| `UNSPECIFIED` (for example `key usage does not include certificate signing`) | Follow the reported TLS reason (such as reissuing the CA with `keyCertSign`). |
|
|
531
|
+
| `https://` proxy certificate rejected | Proxy TLS uses Node.js's CA store, never `sslrootcert`; add the proxy CA to [`NODE_EXTRA_CA_CERTS`](/environment-variables#tls-certificates). |
|
|
532
|
+
| Proxy refused tunnel or unreachable | Allow `<db-host>:<port>` on the proxy, supply credentials for `407`, verify `HTTPS_PROXY`, or bypass with `NO_PROXY` / `proxy: "none"`. |
|
|
533
|
+
| `unsupported-proxy` | Use an `http://` or `https://` proxy (`socks5://` is unsupported). |
|
|
534
|
+
| `StorageTransientError` (`read-only-server`, PG `25006`) | `url` hits a read replica, or the server is failing over / out of disk. Use the read/write endpoint or retry after failover. |
|
|
535
|
+
| `sorry, too many clients already` / `too many connections for role` (PG `53300`) | Server or role hit its connection cap (`connection-refused`). Lower `maxConnections`/`readerMaxConnections`, raise server limits, or deploy [PgBouncer](/storage/postgres/pgbouncer). |
|
|
536
|
+
| `timeout exceeded when trying to connect` | Local pool saturated or connection handshake exceeded `connectTimeoutMs` (`connection-refused`). Raise `maxConnections` or `connectTimeoutMs`. |
|
|
537
|
+
| `prepared statement "atomic_…" does not exist` / `already exists` behind a pooler | Pooler does not retain prepared statements. Atomic disables them automatically for the rest of the process and retries; set `maxPreparedStatements: 0`, or enable `max_prepared_statements > 0` on PgBouncer 1.21+. |
|
|
538
|
+
| `StorageTransientError` (`lock-conflict` / `transaction-timeout`) | Statement waited too long or exceeded `statementTimeoutMs`; nothing was written. Investigate server load if frequent. |
|
|
539
|
+
| `wake-ups: polling only` in `atomic storage status` | Messages still arrive via polling; see [Wake-ups](#wake-ups). |
|
|
540
|
+
| `StorageTransientError` (`connection-lost`) | Server or pooler closed the socket (failover, restart, or idle firewall drop); retry, or lower `keepAliveIdleMs`. |
|