@bastani/atomic 0.10.14 → 0.10.15-alpha.1

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.
Files changed (341) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/_shared/dist-KOELCESV.js +2 -2
  3. package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
  4. package/dist/_shared/lib-4PES5P4V.js +2 -2
  5. package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +3 -3
  6. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +3 -3
  7. package/dist/_shared/mode-shared-2QJSCUM6.js +3 -3
  8. package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
  9. package/dist/_shared/runtime-O4KCSG4C.js +2 -2
  10. package/dist/_shared/{sdk-B5LEWGGI.js → sdk-OHKMDJ74.js} +27 -5
  11. package/dist/_shared/{sdk-B5LEWGGI.js.map → sdk-OHKMDJ74.js.map} +1 -1
  12. package/dist/_shared/session-data-AHTU7IS6.js +2 -2
  13. package/dist/_shared/startup-0-0-Q3MWKUK4.js +2 -2
  14. package/dist/_shared/startup-0-1-M6OWAYHH.js +2 -2
  15. package/dist/_shared/{startup-0-2-5QHPCEON.js → startup-0-2-2HUMCPKX.js} +14 -16
  16. package/dist/_shared/startup-0-2-2HUMCPKX.js.map +1 -0
  17. package/dist/_shared/startup-0-3-4ZYBYQNM.js +3 -3
  18. package/dist/_shared/startup-0-4-ZMJV547D.js +3 -3
  19. package/dist/_shared/startup-0-5-YDW47QX6.js +3 -3
  20. package/dist/_shared/startup-10-0-TDQNBDDL.js +3 -3
  21. package/dist/_shared/startup-14-0-MLX36RBG.js +1 -1
  22. package/dist/_shared/startup-15-0-YUKGAC63.js +1 -1
  23. package/dist/_shared/startup-15-1-4S7FLMNG.js +6 -30
  24. package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
  25. package/dist/_shared/startup-8-0-34CBHPZH.js +3 -3
  26. package/dist/_shared/startup-8-1-LZFXSD3Z.js +3 -3
  27. package/dist/_shared/storage-command-7MGXLJGZ.js +2 -2
  28. package/dist/_shared/storage-status-K7PX2RXA.js +3 -3
  29. package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
  30. package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
  31. package/dist/builtin/intercom/index.bundle.mjs +1 -1
  32. package/dist/builtin/intercom/package.json +1 -1
  33. package/dist/builtin/mcp/index.bundle.mjs +1 -1
  34. package/dist/builtin/mcp/package.json +1 -1
  35. package/dist/builtin/subagents/package.json +1 -1
  36. package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
  37. package/dist/builtin/web-access/index.bundle.mjs +1 -1
  38. package/dist/builtin/web-access/package.json +1 -1
  39. package/dist/cli/auth-cli.code.js +1 -1
  40. package/dist/cli/auth-cli.impl.js +3 -3
  41. package/dist/cli/auth-cli.js +3 -3
  42. package/dist/cli/blueprint-command.impl.js +3 -3
  43. package/dist/cli/blueprint-command.js +3 -3
  44. package/dist/cli/intercom-command.code.js +3 -3
  45. package/dist/cli/intercom-command.impl.js +3 -3
  46. package/dist/cli/intercom-command.js +3 -3
  47. package/dist/cli/list-models.impl.js +3 -3
  48. package/dist/cli/list-models.js +3 -3
  49. package/dist/cli/session-picker.code.js +1 -1
  50. package/dist/cli/session-picker.impl.js +3 -3
  51. package/dist/cli/session-picker.js +3 -3
  52. package/dist/cli/startup-ui.code.js +1 -1
  53. package/dist/cli/startup-ui.impl.js +3 -3
  54. package/dist/cli/startup-ui.js +3 -3
  55. package/dist/cli/storage-command.impl.js +3 -3
  56. package/dist/cli/storage-command.js +3 -3
  57. package/dist/cli/storage-search-session.code.js +1 -1
  58. package/dist/cli/storage-search-session.impl.js +3 -3
  59. package/dist/cli/storage-search-session.js +3 -3
  60. package/dist/cli/team-command.code.js +1 -1
  61. package/dist/cli/team-command.impl.js +3 -3
  62. package/dist/cli/team-command.js +3 -3
  63. package/dist/cli.js +2 -2
  64. package/dist/core/compaction/compactor.d.ts +0 -8
  65. package/dist/core/debug.impl.js +3 -3
  66. package/dist/core/debug.js +3 -3
  67. package/dist/core/export-html/card-projection.impl.js +3 -3
  68. package/dist/core/export-html/card-projection.js +3 -3
  69. package/dist/core/export-html/index.code.js +2 -2
  70. package/dist/core/export-html/index.impl.js +3 -3
  71. package/dist/core/export-html/index.js +3 -3
  72. package/dist/core/export-html/json-spans.impl.js +3 -3
  73. package/dist/core/export-html/json-spans.js +3 -3
  74. package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
  75. package/dist/core/export-html/oversized-render-inputs.js +3 -3
  76. package/dist/core/export-html/tool-renderer.impl.js +3 -3
  77. package/dist/core/export-html/tool-renderer.js +3 -3
  78. package/dist/core/extensions/jiti-loader.impl.js +3 -3
  79. package/dist/core/extensions/jiti-loader.js +3 -3
  80. package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
  81. package/dist/core/extensions/jiti-static-loader.js +3 -3
  82. package/dist/core/extensions/loader-host-modules.impl.js +3 -3
  83. package/dist/core/extensions/loader-host-modules.js +3 -3
  84. package/dist/core/intercom-broker-control-host.code.js +1 -1
  85. package/dist/core/intercom-broker-control-host.impl.js +3 -3
  86. package/dist/core/intercom-broker-control-host.js +3 -3
  87. package/dist/core/intercom-broker-control.code.js +2 -2
  88. package/dist/core/intercom-broker-control.impl.js +3 -3
  89. package/dist/core/intercom-broker-control.js +3 -3
  90. package/dist/core/package-manager-storage-adapters.impl.js +3 -3
  91. package/dist/core/package-manager-storage-adapters.js +3 -3
  92. package/dist/core/sdk.code.js +1 -1
  93. package/dist/core/sdk.impl.js +3 -3
  94. package/dist/core/sdk.js +3 -3
  95. package/dist/core/session-manager-core.js +3 -3
  96. package/dist/core/session-manager-list.impl.js +3 -3
  97. package/dist/core/session-manager-list.js +3 -3
  98. package/dist/core/session-manager.impl.js +3 -3
  99. package/dist/core/session-manager.js +3 -3
  100. package/dist/core/session-storage.impl.js +3 -3
  101. package/dist/core/session-storage.js +3 -3
  102. package/dist/core/storage/index.js +2 -2
  103. package/dist/core/storage/node-sqlite-thread.js +2 -2
  104. package/dist/core/storage/node-sqlite.js +2 -2
  105. package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
  106. package/dist/core/storage/offline-snapshot-file.js +3 -3
  107. package/dist/core/storage/provider.js +2 -2
  108. package/dist/core/storage/selection.js +2 -2
  109. package/dist/core/storage/session/branch-fork-source.code.js +2 -2
  110. package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
  111. package/dist/core/storage/session/branch-fork-source.js +3 -3
  112. package/dist/core/storage/session/card-view.impl.js +3 -3
  113. package/dist/core/storage/session/card-view.js +3 -3
  114. package/dist/core/storage/session/child-reader.code.js +2 -2
  115. package/dist/core/storage/session/child-reader.impl.js +3 -3
  116. package/dist/core/storage/session/child-reader.js +3 -3
  117. package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
  118. package/dist/core/storage/session/chunked-resume-projection.js +3 -3
  119. package/dist/core/storage/session/expanded-child-details.code.js +2 -2
  120. package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
  121. package/dist/core/storage/session/expanded-child-details.js +3 -3
  122. package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
  123. package/dist/core/storage/session/fork-row-bytes.js +3 -3
  124. package/dist/core/storage/session/fork-row-index.impl.js +3 -3
  125. package/dist/core/storage/session/fork-row-index.js +3 -3
  126. package/dist/core/storage/session/fork-staging.code.js +1 -1
  127. package/dist/core/storage/session/fork-staging.impl.js +3 -3
  128. package/dist/core/storage/session/fork-staging.js +3 -3
  129. package/dist/core/storage/session/fork-window.code.js +2 -2
  130. package/dist/core/storage/session/fork-window.impl.js +3 -3
  131. package/dist/core/storage/session/fork-window.js +3 -3
  132. package/dist/core/storage/session/history-pages.impl.js +3 -3
  133. package/dist/core/storage/session/history-pages.js +3 -3
  134. package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
  135. package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
  136. package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
  137. package/dist/core/storage/session/jsonl-session-store.js +3 -3
  138. package/dist/core/storage/session/memory-session-store.impl.js +3 -3
  139. package/dist/core/storage/session/memory-session-store.js +3 -3
  140. package/dist/core/storage/session/pinned-branch-resume.code.js +2 -2
  141. package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
  142. package/dist/core/storage/session/pinned-branch-resume.js +3 -3
  143. package/dist/core/storage/session/released-history-files.code.js +1 -1
  144. package/dist/core/storage/session/released-history-files.impl.js +3 -3
  145. package/dist/core/storage/session/released-history-files.js +3 -3
  146. package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
  147. package/dist/core/storage/session/resident-fork-rows.js +3 -3
  148. package/dist/core/storage/session/session-resume.impl.js +3 -3
  149. package/dist/core/storage/session/session-resume.js +3 -3
  150. package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
  151. package/dist/core/storage/session/snapshot-cut.js +3 -3
  152. package/dist/core/storage/session/snapshot-history.code.js +2 -2
  153. package/dist/core/storage/session/snapshot-history.impl.js +3 -3
  154. package/dist/core/storage/session/snapshot-history.js +3 -3
  155. package/dist/core/storage/session/sql-session-store.code.js +1 -1
  156. package/dist/core/storage/session/sql-session-store.impl.js +3 -3
  157. package/dist/core/storage/session/sql-session-store.js +3 -3
  158. package/dist/core/storage/session/tree-outline.impl.js +3 -3
  159. package/dist/core/storage/session/tree-outline.js +3 -3
  160. package/dist/core/storage/session/tree-presentation.impl.js +3 -3
  161. package/dist/core/storage/session/tree-presentation.js +3 -3
  162. package/dist/core/storage/storage-status.impl.js +3 -3
  163. package/dist/core/storage/storage-status.js +3 -3
  164. package/dist/core/storage/team.impl.js +3 -3
  165. package/dist/core/storage/team.js +3 -3
  166. package/dist/core/structured-output/index.code.js +1 -1
  167. package/dist/core/structured-output/index.impl.js +3 -3
  168. package/dist/core/structured-output/index.js +3 -3
  169. package/dist/core/tasks/task-completion-entry.impl.js +3 -3
  170. package/dist/core/tasks/task-completion-entry.js +3 -3
  171. package/dist/core/tasks/task-file-history.code.js +2 -2
  172. package/dist/core/tasks/task-file-history.impl.js +3 -3
  173. package/dist/core/tasks/task-file-history.js +3 -3
  174. package/dist/core/tasks/task-reference-archive.code.js +2 -2
  175. package/dist/core/tasks/task-reference-archive.js +3 -3
  176. package/dist/core/tasks/task-reference-identity.js +3 -3
  177. package/dist/core/tasks/task-reference-stream.impl.js +3 -3
  178. package/dist/core/tasks/task-reference-stream.js +3 -3
  179. package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
  180. package/dist/core/tasks/task-unsaved-answer.js +3 -3
  181. package/dist/core/tasks/task-view-source.impl.js +3 -3
  182. package/dist/core/tasks/task-view-source.js +3 -3
  183. package/dist/core/tools/read-url.impl.js +3 -3
  184. package/dist/core/tools/read-url.js +3 -3
  185. package/dist/core/worktree-snapshot/blob-store.js +2 -2
  186. package/dist/core/worktree-snapshot/errors.code.js +1 -1
  187. package/dist/core/worktree-snapshot/errors.impl.js +3 -3
  188. package/dist/core/worktree-snapshot/errors.js +3 -3
  189. package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
  190. package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
  191. package/dist/extensions/codemode/execute.impl.js +3 -3
  192. package/dist/extensions/codemode/execute.js +3 -3
  193. package/dist/extensions/codemode/renderer.impl.js +3 -3
  194. package/dist/extensions/codemode/renderer.js +3 -3
  195. package/dist/extensions/mcp/cli.code.js +1 -1
  196. package/dist/extensions/mcp/cli.impl.js +3 -3
  197. package/dist/extensions/mcp/cli.js +3 -3
  198. package/dist/extensions/mcp/cli.lazy.code.js +2 -2
  199. package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
  200. package/dist/extensions/mcp/cli.lazy.js +3 -3
  201. package/dist/extensions/mcp/runtime.code.js +1 -1
  202. package/dist/extensions/mcp/runtime.impl.js +3 -3
  203. package/dist/extensions/mcp/runtime.js +3 -3
  204. package/dist/index.d.ts +21 -1
  205. package/dist/index.js +2 -2
  206. package/dist/main-first-time-setup.code.js +1 -1
  207. package/dist/main-first-time-setup.impl.js +3 -3
  208. package/dist/main-first-time-setup.js +3 -3
  209. package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
  210. package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
  211. package/dist/modes/interactive/components/stored-tree-view.js +3 -3
  212. package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
  213. package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
  214. package/dist/modes/print-mode.js +1 -1
  215. package/dist/package-manager-cli.code.js +2 -2
  216. package/dist/package-manager-cli.impl.js +3 -3
  217. package/dist/package-manager-cli.js +3 -3
  218. package/dist/startup-files.json +1 -1
  219. package/dist/startup-stages/6.js +1 -1
  220. package/dist/utils/startup-database-spare.code.js +1 -1
  221. package/dist/utils/startup-database-spare.impl.js +3 -3
  222. package/dist/utils/startup-database-spare.js +3 -3
  223. package/dist/utils/tools-manager.impl.js +3 -3
  224. package/dist/utils/tools-manager.js +3 -3
  225. package/docs/background-tasks/reference.md +182 -0
  226. package/docs/background-tasks.md +98 -405
  227. package/docs/build.md +67 -27
  228. package/docs/changelog.mdx +1 -1
  229. package/docs/codemode.md +108 -39
  230. package/docs/compaction/branch-summaries.md +54 -0
  231. package/docs/compaction/custom-compactors.md +161 -0
  232. package/docs/compaction/memory-compaction.md +77 -0
  233. package/docs/compaction/reference.md +86 -38
  234. package/docs/compaction.md +51 -252
  235. package/docs/computer-use.md +169 -321
  236. package/docs/containerization.md +71 -57
  237. package/docs/custom-provider/api-reference.md +119 -25
  238. package/docs/custom-provider/oauth.md +114 -132
  239. package/docs/custom-provider/override.md +37 -27
  240. package/docs/custom-provider/registration.md +107 -83
  241. package/docs/custom-provider/streaming.md +85 -71
  242. package/docs/custom-provider.md +85 -52
  243. package/docs/development.md +39 -29
  244. package/docs/docs.json +76 -63
  245. package/docs/environment-variables.md +94 -44
  246. package/docs/extensions/api-reference.md +86 -43
  247. package/docs/extensions/authoring.md +162 -154
  248. package/docs/extensions/events.md +80 -25
  249. package/docs/extensions/examples.md +90 -85
  250. package/docs/extensions/ui.md +206 -82
  251. package/docs/extensions.md +79 -108
  252. package/docs/getting-started/authentication.md +67 -36
  253. package/docs/getting-started/first-session.md +53 -43
  254. package/docs/getting-started/installation.md +116 -89
  255. package/docs/getting-started/project-instructions.md +48 -34
  256. package/docs/guides/configuration.md +82 -20
  257. package/docs/guides/non-interactive.md +66 -24
  258. package/docs/guides/resume-on-any-machine.md +135 -82
  259. package/docs/guides/team-setup.md +114 -105
  260. package/docs/guides.md +76 -32
  261. package/docs/herdr.md +15 -16
  262. package/docs/how-atomic-works.md +140 -0
  263. package/docs/index.md +58 -44
  264. package/docs/intercom/operations.md +141 -151
  265. package/docs/intercom/reference.md +85 -108
  266. package/docs/intercom.md +84 -145
  267. package/docs/json.md +120 -67
  268. package/docs/keybindings.md +85 -49
  269. package/docs/libraries/agent-core.md +137 -275
  270. package/docs/libraries/ai.md +100 -84
  271. package/docs/libraries/codemode.md +210 -300
  272. package/docs/libraries/schema.md +59 -53
  273. package/docs/libraries/storage-postgres.md +49 -35
  274. package/docs/libraries/telemetry.md +153 -354
  275. package/docs/libraries/tui.md +265 -393
  276. package/docs/libraries.md +42 -26
  277. package/docs/llama-cpp.md +171 -161
  278. package/docs/mcp-servers.md +90 -51
  279. package/docs/models/choose-a-model.md +188 -0
  280. package/docs/models/reference.md +74 -30
  281. package/docs/models.md +153 -88
  282. package/docs/orchestration/migrating-workflows.md +23 -16
  283. package/docs/orchestration/patterns.md +39 -44
  284. package/docs/orchestration.md +65 -26
  285. package/docs/packages/authoring.md +51 -29
  286. package/docs/packages/reference.md +42 -21
  287. package/docs/packages.md +69 -58
  288. package/docs/programmatic.md +118 -24
  289. package/docs/prompt-templates.md +84 -83
  290. package/docs/providers/reference.md +43 -48
  291. package/docs/providers.md +219 -451
  292. package/docs/quickstart.md +140 -120
  293. package/docs/reference/cli.md +135 -97
  294. package/docs/reference.md +20 -18
  295. package/docs/rpc/examples.md +76 -20
  296. package/docs/rpc/extension-ui.md +64 -38
  297. package/docs/rpc/protocol.md +361 -110
  298. package/docs/rpc.md +57 -17
  299. package/docs/sdk/reference.md +409 -534
  300. package/docs/sdk/storage.md +53 -13
  301. package/docs/sdk/structured-decisions.md +82 -56
  302. package/docs/sdk/web-server.md +57 -43
  303. package/docs/sdk.md +106 -84
  304. package/docs/security.md +42 -64
  305. package/docs/session-format.md +62 -38
  306. package/docs/sessions.md +99 -214
  307. package/docs/settings.md +165 -195
  308. package/docs/shell-aliases.md +9 -6
  309. package/docs/skills/authoring.md +69 -48
  310. package/docs/skills/reference.md +51 -20
  311. package/docs/skills.md +99 -148
  312. package/docs/slash-commands.md +129 -0
  313. package/docs/storage/custom-adapters.md +160 -85
  314. package/docs/storage/jsonl.md +81 -66
  315. package/docs/storage/postgres/pgbouncer.md +120 -126
  316. package/docs/storage/postgres/tuning.md +120 -143
  317. package/docs/storage/postgres.md +314 -330
  318. package/docs/storage/sqlite.md +71 -42
  319. package/docs/storage.md +298 -302
  320. package/docs/subagents/authoring.md +55 -38
  321. package/docs/subagents/reference.md +73 -33
  322. package/docs/subagents.md +119 -187
  323. package/docs/terminal-setup.md +50 -38
  324. package/docs/termux.md +67 -41
  325. package/docs/themes/reference.md +23 -19
  326. package/docs/themes.md +142 -127
  327. package/docs/tmux.md +47 -55
  328. package/docs/tools.md +147 -109
  329. package/docs/tui/reference.md +166 -214
  330. package/docs/tui.md +196 -341
  331. package/docs/usage.md +118 -138
  332. package/docs/verification.md +79 -51
  333. package/docs/web-access.md +121 -101
  334. package/docs/windows.md +26 -27
  335. package/docs/worktree-snapshots/reference.md +245 -0
  336. package/docs/worktree-snapshots.md +71 -259
  337. package/package.json +8 -8
  338. package/dist/_shared/startup-0-2-5QHPCEON.js.map +0 -1
  339. package/docs/guides/intercom.md +0 -32
  340. package/docs/guides/orchestration.md +0 -28
  341. package/docs/guides/subagents.md +0 -37
@@ -1,24 +1,24 @@
1
1
  ---
2
2
  title: "Tune PostgreSQL for many agents"
3
3
  sidebarTitle: "Server tuning"
4
- description: "Server-side tuning for a PostgreSQL database shared by many Atomic agents: where the time goes, distance, connections, memory, monitoring, busy tables, and what to leave alone."
4
+ description: "Server-side tuning for a PostgreSQL database shared by many Atomic agents: network distance, connections, memory and huge pages, query profiling, busy tables, compression, and upgrades."
5
5
  ---
6
6
 
7
- This guide is for the person who runs the PostgreSQL server that Atomic's agents share. Use it after you set up the database as in [PostgreSQL setup](/storage/postgres).
7
+ This guide covers server-side tuning for the PostgreSQL instance behind your Atomic fleet. Complete [PostgreSQL setup](/storage/postgres) first.
8
8
 
9
- The table names below assume Atomic's default schema, `atomic`, and no `prefix`, which is the default. With a prefix, each table name starts with it. For example, with `prefix: "team_"`, `atomic.session_sessions` becomes `atomic.team_session_sessions`.
9
+ Table names below assume the default schema (`atomic`) and no `prefix`. When a `prefix` is configured, every table name starts with it (for example, `prefix: "team_"` maps `atomic.session_sessions` to `atomic.team_session_sessions`).
10
10
 
11
11
  ## Where the time goes
12
12
 
13
- Three things usually limit how fast Atomic's agents work with the server:
13
+ Three bottlenecks typically limit multi-agent throughput on PostgreSQL:
14
14
 
15
- - **Round trips.** Each save waits for answers from the server. The farther away the server, the longer each wait.
16
- - **Connections.** Each server has a fixed number. When agents need more than it has, they get errors.
17
- - **Locks.** Agents that write the same data wait for each other.
15
+ - **Round trips:** Every save waits for the server to acknowledge it; higher network latency adds directly to every save and lock hold time.
16
+ - **Connections:** Exceeding `max_connections` rejects new work with errors.
17
+ - **Locks:** Agents writing to the same session wait in line for each other.
18
18
 
19
- To tell which one you are hitting, run these as an administrator. Replace `atomic` with your database's name.
19
+ Run these diagnostic queries as an administrator (replace `atomic` with your database name):
20
20
 
21
- How many connections are in use, and what they are doing. `active` means running a query, and `idle` means open but unused:
21
+ Connections by state (`active` = executing a query; `idle` = open and waiting):
22
22
 
23
23
  ```sql
24
24
  SELECT state, count(*)
@@ -28,7 +28,7 @@ GROUP BY state
28
28
  ORDER BY 2 DESC;
29
29
  ```
30
30
 
31
- What the busy connections are waiting for. A large count with `wait_event_type` `Lock` means lock waits. `Client` with `ClientRead` means the server waits for the agent, which usually means distance:
31
+ What non-idle connections are waiting on (`Lock` indicates contention; `Client` / `ClientRead` typically reflects network round-trip latency):
32
32
 
33
33
  ```sql
34
34
  SELECT wait_event_type, wait_event, count(*)
@@ -38,7 +38,7 @@ GROUP BY 1, 2
38
38
  ORDER BY 3 DESC;
39
39
  ```
40
40
 
41
- How close the server is to its connection limit:
41
+ Current client connections vs. `max_connections`:
42
42
 
43
43
  ```sql
44
44
  SELECT count(*) AS used, current_setting('max_connections')::int AS max
@@ -46,33 +46,29 @@ FROM pg_stat_activity
46
46
  WHERE backend_type = 'client backend';
47
47
  ```
48
48
 
49
- On the machine itself, `uptime` shows the load average. If it stays well below the number of CPU cores while agents are slow, the server is waiting, not working.
49
+ On the database host itself, check `uptime`: if load average sits well below CPU core count while agents feel slow, the workload is waiting on network latency or locks rather than CPU.
50
50
 
51
51
  ## Put the database close to the agents
52
52
 
53
- Each save waits for at least one round trip: the time a message takes to reach the server and come back, which `ping` shows. So every save takes at least that long:
53
+ Every save waits for at least one network round trip, and transactions hold their locks across those round trips:
54
54
 
55
- | Distance to the server | One round trip, and each save at least |
55
+ | Distance to PostgreSQL | Typical round trip (minimum per save) |
56
56
  | --- | --- |
57
- | Same data center | about 1 ms |
58
- | Same region, different zone | about 2 ms |
59
- | Across a continent | about 80 ms |
57
+ | Same data center | ~1 ms |
58
+ | Same region, different availability zone | ~2 ms |
59
+ | Cross-continent | ~80 ms |
60
60
 
61
- Saves wait twice as long until the owner has run `atomic storage migrate` after an upgrade. See [After you upgrade Atomic](#after-you-upgrade-atomic).
62
-
63
- Distance also makes every lock wait longer, because a transaction holds its locks for its round trips.
64
-
65
- Run the server in the same region as the agents, and ideally the same zone. No server setting makes up for distance.
61
+ Run PostgreSQL in the same region—and ideally the same availability zone—as your agents. No server parameter compensates for network distance. Also run `atomic storage migrate` after upgrades so session appends use the single-round-trip path instead of two round trips (see [After you upgrade Atomic](#after-you-upgrade-atomic)).
66
62
 
67
63
  ## Connections
68
64
 
69
- Each Atomic process opens up to `maxConnections` plus `readerMaxConnections` connections to the server, 10 by default. An Intercom broker process opens one more, for wake-ups. [Count the connections Atomic needs](/storage/postgres#count-the-connections-atomic-needs) explains the arithmetic, and [Tuning for many concurrent agents](/storage/postgres#tuning-for-many-concurrent-agents) shows how to size `maxConnections`.
65
+ Each Atomic process opens up to `maxConnections + readerMaxConnections` connections (10 by default), plus 1 wake-up connection per Intercom broker. See [Count the connections Atomic needs](/storage/postgres#count-the-connections-atomic-needs) and [Tuning for many concurrent agents](/storage/postgres#tuning-for-many-concurrent-agents) for sizing.
70
66
 
71
67
  On the server:
72
68
 
73
- - **`max_connections`** is the total the server accepts. Each connection uses memory for its own work, so the server cannot accept unlimited connections. Set it high enough for Atomic's connections, or PgBouncer's pool, plus one wake-up connection per broker and room for administrators. Changing it needs a restart.
74
- - **Per-role limits.** `ALTER ROLE atomic_runtime CONNECTION LIMIT <n>;` caps one role, so a runaway fleet cannot take every slot. Set `<n>` to the connections Atomic needs, or PgBouncer's pool, plus one wake-up connection per broker, plus a margin. The example below uses 300. [Connection limits](/storage/postgres/pgbouncer#connection-limits) works one out.
75
- - **PgBouncer.** When agents need more connections than the server can give, put [PgBouncer](/storage/postgres/pgbouncer) in front.
69
+ - **`max_connections`** (requires restart): set high enough for Atomic's connections (or PgBouncer's server pool), one wake-up connection per broker, and admin/monitoring overhead.
70
+ - **Per-role cap:** cap `atomic_runtime` to PgBouncer's pool plus broker wake-ups plus a safety margin so a fleet surge cannot starve administrators (see [Connection limits](/storage/postgres/pgbouncer#connection-limits)).
71
+ - **Connection pooler:** deploy [PgBouncer](/storage/postgres/pgbouncer) when fleet demand exceeds `max_connections`.
76
72
 
77
73
  ```sql
78
74
  SHOW max_connections;
@@ -83,69 +79,75 @@ ALTER ROLE atomic_runtime CONNECTION LIMIT 300;
83
79
 
84
80
  ### Shared buffers
85
81
 
86
- `shared_buffers` is the memory PostgreSQL keeps for table and index pages. A common starting point is a quarter of the machine's memory, for example `shared_buffers = 8GB` on a machine with 32 GB. Atomic's data is usually small enough to fit, so a larger value rarely helps. Changing it needs a restart.
82
+ `shared_buffers` controls PostgreSQL's shared page cache (requires restart). A good starting point is 25% of host RAM (for example `shared_buffers = 8GB` on a 32 GB host). Atomic's working set usually fits comfortably inside this cache, so allocating much more rarely helps.
87
83
 
88
84
  ### Huge pages
89
85
 
90
- The operating system tracks memory in pages, usually 4 KB each. Every server process that touches shared memory keeps its own table of those pages. With 8 GB of shared buffers and hundreds of connections, those tables alone can take gigabytes. Huge pages are 2 MB each on Linux, so the tables are 512 times smaller.
91
-
92
- PostgreSQL uses huge pages when `huge_pages` is `try` (the default) or `on`, and the operating system has enough of them reserved. With `huge_pages = try` and none reserved, `huge_pages_status` is `off`. To reserve them on Linux:
93
-
94
- 1. **Find out how many pages PostgreSQL needs.** Stop the server first, because PostgreSQL answers this only while it is not running. Then run the server program as the `postgres` user, with your data directory and configuration file. On Debian and Ubuntu, with PostgreSQL 18, replace 18 with your version:
95
-
96
- ```bash
97
- sudo -u postgres /usr/lib/postgresql/18/bin/postgres -D /var/lib/postgresql/18/main -C shared_memory_size_in_huge_pages -c config_file=/etc/postgresql/18/main/postgresql.conf
98
- ```
99
-
100
- Elsewhere, `postgres` is usually on the `postgres` user's `PATH`, and the configuration file is in the data directory, so `-D <data directory>` is enough. It prints a number of pages, for example `4259`.
86
+ Linux normally tracks memory in 4 KB pages, and every PostgreSQL backend keeps its own page-table entries for shared memory. With large `shared_buffers` and hundreds of connections, page tables alone can consume gigabytes. Linux 2 MB huge pages shrink those page tables by 512×.
101
87
 
102
- 2. **Reserve a little more than that**, rounded up, and keep it across reboots. For example, for 4259 pages, reserve 4350:
88
+ PostgreSQL uses huge pages automatically when `huge_pages` is `try` (default) or `on` and enough huge pages are reserved at the OS level. Managed services configure huge pages for you; on self-hosted Linux:
103
89
 
104
- ```bash
105
- echo 'vm.nr_hugepages = 4350' | sudo tee /etc/sysctl.d/60-postgresql-hugepages.conf
106
- sudo sysctl -p /etc/sysctl.d/60-postgresql-hugepages.conf
107
- grep HugePages_Total /proc/meminfo
108
- ```
90
+ <Steps>
91
+ <Step title="Ask PostgreSQL how many huge pages it needs">
92
+ Stop PostgreSQL first (`-C` reads this only while stopped), then run `postgres` as the `postgres` user (on Debian/Ubuntu, adjust `18` for your PostgreSQL version):
109
93
 
110
- 3. **Start the server and check** that it uses them:
94
+ ```bash
95
+ sudo -u postgres /usr/lib/postgresql/18/bin/postgres -D /var/lib/postgresql/18/main -C shared_memory_size_in_huge_pages -c config_file=/etc/postgresql/18/main/postgresql.conf
96
+ ```
111
97
 
112
- ```sql
113
- SHOW huge_pages_status;
114
- ```
98
+ Elsewhere, `postgres -D <data-dir> -C shared_memory_size_in_huge_pages` is usually enough. Note the printed count (for example `4259`).
99
+ </Step>
100
+ <Step title="Reserve slightly more pages persistently">
101
+ Round up with headroom (for example `4350` for `4259` needed):
115
102
 
116
- It should say `on`. `huge_pages_status` exists in PostgreSQL 17 and later. On any version, `HugePages_Rsvd` in `/proc/meminfo` should be close to the number PostgreSQL needed.
103
+ ```bash
104
+ echo 'vm.nr_hugepages = 4350' | sudo tee /etc/sysctl.d/60-postgresql-hugepages.conf
105
+ sudo sysctl -p /etc/sysctl.d/60-postgresql-hugepages.conf
106
+ grep HugePages_Total /proc/meminfo
107
+ ```
108
+ </Step>
109
+ <Step title="Start PostgreSQL and verify">
110
+ ```sql
111
+ SHOW huge_pages_status;
112
+ ```
117
113
 
118
- Reserved huge pages are taken out of the memory other programs can use, even while PostgreSQL is stopped. To undo the reservation, stop the server and set `vm.nr_hugepages` back to `0`.
114
+ Expect `on` (PostgreSQL 17+; on PostgreSQL 16, verify `HugePages_Rsvd` in `/proc/meminfo` matches the expected count).
115
+ </Step>
116
+ </Steps>
119
117
 
120
- Managed services decide huge pages for you.
118
+ <Note>
119
+ Reserved huge pages remain unavailable to other host processes even when PostgreSQL is stopped. To release them, stop PostgreSQL and set `vm.nr_hugepages = 0`.
120
+ </Note>
121
121
 
122
122
  ## See what is slow
123
123
 
124
- `pg_stat_statements` is an extension that records how often each query runs and how long it takes in total. It shows which of the agents' queries take the server's time.
124
+ Use `pg_stat_statements` to measure total and per-call execution time across all agent queries:
125
125
 
126
- 1. **Load it at server start.** Add this line to `postgresql.conf`, or to a file in its `conf.d` directory, and restart:
126
+ <Steps>
127
+ <Step title="Preload pg_stat_statements and restart PostgreSQL">
128
+ Add to `postgresql.conf` (or append to an existing comma-separated list):
127
129
 
128
- ```ini
129
- shared_preload_libraries = 'pg_stat_statements'
130
- ```
130
+ ```ini
131
+ shared_preload_libraries = 'pg_stat_statements'
132
+ ```
133
+ </Step>
134
+ <Step title="Create the extension as a superuser or managed-service admin">
135
+ ```sql
136
+ CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
137
+ ```
138
+ </Step>
139
+ <Step title="Grant stats visibility to your monitoring role">
140
+ Without `pg_read_all_stats`, a role can inspect only its own query text:
131
141
 
132
- If the line already lists other libraries, add it to the list, separated by a comma.
142
+ ```sql
143
+ GRANT pg_read_all_stats TO atomic_owner;
144
+ ```
145
+ </Step>
146
+ </Steps>
133
147
 
134
- 2. **Create the extension** in Atomic's database, as a superuser or your managed service's administrator role. The owner role is not enough.
148
+ Run these queries in the `atomic` database:
135
149
 
136
- ```sql
137
- CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
138
- ```
139
-
140
- 3. **Let the role you monitor with see every query.** Without this, a role sees the text only of its own queries. This example grants it to the owner role:
141
-
142
- ```sql
143
- GRANT pg_read_all_stats TO atomic_owner;
144
- ```
145
-
146
- Run these queries in the `atomic` database.
147
-
148
- The queries that take the most total time. Look here first:
150
+ Top queries by total execution time (start here):
149
151
 
150
152
  ```sql
151
153
  SELECT calls, round(total_exec_time) AS total_ms, round(mean_exec_time::numeric, 2) AS mean_ms,
@@ -155,7 +157,7 @@ ORDER BY total_exec_time DESC
155
157
  LIMIT 10;
156
158
  ```
157
159
 
158
- The slowest queries on average:
160
+ Slowest frequent queries on average:
159
161
 
160
162
  ```sql
161
163
  SELECT calls, round(mean_exec_time::numeric, 2) AS mean_ms, round(max_exec_time::numeric, 2) AS max_ms,
@@ -166,7 +168,7 @@ ORDER BY mean_exec_time DESC
166
168
  LIMIT 10;
167
169
  ```
168
170
 
169
- How much of the time is lock waits. Atomic takes its locks with `pg_advisory_xact_lock`, so a large share here means agents wait for each other, not for the server:
171
+ Share of total execution time spent waiting on Atomic's advisory locks (`pg_advisory_xact_lock`—a high percentage means agents are contending on the same data rather than waiting on PostgreSQL):
170
172
 
171
173
  ```sql
172
174
  SELECT round((100 * sum(total_exec_time) FILTER (WHERE query LIKE '%pg_advisory%')
@@ -174,7 +176,7 @@ SELECT round((100 * sum(total_exec_time) FILTER (WHERE query LIKE '%pg_advisory%
174
176
  FROM pg_stat_statements;
175
177
  ```
176
178
 
177
- To start a new measurement, clear the counters:
179
+ Reset counters before starting a fresh measurement window:
178
180
 
179
181
  ```sql
180
182
  SELECT pg_stat_statements_reset();
@@ -182,27 +184,25 @@ SELECT pg_stat_statements_reset();
182
184
 
183
185
  ## Busy small tables
184
186
 
185
- A few of Atomic's tables are small but change constantly:
187
+ Three small tables receive frequent updates:
186
188
 
187
- | Table | What changes it |
189
+ | Table | Update pattern |
188
190
  | --- | --- |
189
191
  | `atomic.session_sessions` | One row per session, updated on every save |
190
- | `atomic.intercom_leases` | Leases that Intercom brokers renew every few seconds |
191
- | `atomic.snapshot_session_links` | Links between sessions and worktree snapshots, updated when sessions change |
192
+ | `atomic.intercom_leases` | Broker membership and presence leases renewed every 10 seconds |
193
+ | `atomic.snapshot_session_links` | Parent/child worktree snapshot links updated as sessions append entries |
192
194
 
193
195
  ### Clean them up sooner
194
196
 
195
- PostgreSQL never changes a row in place. An update writes a new version of the row and leaves the old one behind as a dead row. A background process, autovacuum, later frees the dead rows. By default it waits until a fifth of a table is dead. On a small table that changes constantly, that can mean many dead rows between cleanups, and queries that read past them.
196
-
197
- `atomic storage migrate`, run as the owner role, tells autovacuum to clean these tables after a fixed number of dead rows instead: 500 for `session_sessions` and `intercom_leases`, and 1000 for `snapshot_session_links`. You do not set it yourself.
197
+ Because PostgreSQL uses MVCC, every update leaves a dead tuple until autovacuum reclaims it. PostgreSQL's default 20% dead-tuple ratio can let thousands of dead versions accumulate on small, hot tables.
198
198
 
199
- The settings take effect at once, with no restart. Migrate keeps any value you have set on these tables yourself. To use a different threshold, set it and migrate leaves it alone:
199
+ `atomic storage migrate` (run as the owner role) automatically configures fixed dead-tuple autovacuum thresholds: `500` for `session_sessions` and `intercom_leases`, and `1000` for `snapshot_session_links`. No restart is needed, and `migrate` preserves any custom threshold you have set manually:
200
200
 
201
201
  ```sql
202
202
  ALTER TABLE atomic.session_sessions SET (autovacuum_vacuum_threshold = 2000);
203
203
  ```
204
204
 
205
- Check dead rows and the last cleanup with:
205
+ Inspect live vs. dead tuples and last cleanup time:
206
206
 
207
207
  ```sql
208
208
  SELECT relname, n_live_tup, n_dead_tup, last_autovacuum
@@ -210,19 +210,18 @@ FROM pg_stat_user_tables
210
210
  WHERE relname IN ('session_sessions', 'intercom_leases', 'snapshot_session_links');
211
211
  ```
212
212
 
213
- Tables that only grow, such as `session_entries`, keep PostgreSQL's defaults. Since PostgreSQL 13, autovacuum also visits a table after enough inserts, and Atomic reads those tables by key, so it gains nothing from cleaning them more often.
213
+ Append-only tables like `session_entries` keep PostgreSQL's default autovacuum settings.
214
214
 
215
215
  ### Updates that stay on their page
216
216
 
217
- When PostgreSQL writes a row's new version on the same page as the old one, and the update changes no indexed column, it can skip updating the table's indexes. This is called a HOT update, for heap-only tuple. It is faster and leaves less to clean up. It only works when the page has free space.
217
+ When an updated row version fits on the same 8 KB page and modifies no indexed column, PostgreSQL performs a **HOT (Heap-Only Tuple)** update—skipping index writes and reducing bloat.
218
218
 
219
- `fillfactor` leaves part of every page free for this. Atomic sets `fillfactor = 80` on `session_sessions` and `intercom_leases`, leaving a fifth of each page free, and `fillfactor = 85` on `intercom_outbox`, whose messages Intercom brokers update while they deliver them, when you run `atomic storage migrate`. You do not set it yourself.
219
+ `atomic storage migrate` configures this automatically:
220
220
 
221
- `fillfactor` applies to pages written after the change. To rewrite existing pages, run `VACUUM FULL` on the table, which locks it while it runs, or use `pg_repack`. This is optional.
221
+ - Sets `fillfactor = 80` on `session_sessions` and `intercom_leases`, and `fillfactor = 85` on `intercom_outbox`, leaving free space on new pages for in-place HOT updates. (Rewriting pre-existing pages via `VACUUM FULL`—which locks the table—or `pg_repack` is optional.)
222
+ - Replaces the legacy `snapshot_session_links_leaves` partial index (which filtered on `children = 0`) with `snapshot_session_links_anchored` (`WHERE anchor_seq IS NOT NULL`), built concurrently without blocking writes. Because no index references `children` anymore, parent-link `children` increments on session appends stay HOT updates whenever the page has free space. Combined with the autovacuum threshold (`1000`), this keeps `snapshot_session_links` compact and fast.
222
223
 
223
- `snapshot_session_links` gets few or no HOT updates. Its updates change a column that one of its indexes depends on, so free space does not help. The autovacuum settings above keep it small.
224
-
225
- Check the share of HOT updates per table with:
224
+ Check HOT update ratios per table:
226
225
 
227
226
  ```sql
228
227
  SELECT relname, n_tup_upd, n_tup_hot_upd,
@@ -233,21 +232,15 @@ WHERE relname IN ('session_sessions', 'intercom_leases', 'intercom_outbox', 'sna
233
232
 
234
233
  ### The search index
235
234
 
236
- Atomic indexes session text for history search with a trigram index, `atomic.session_search_trgm`. This kind of index (GIN) does not add new text to the index right away. It first puts it in a holding area, the pending list, and later moves the whole list into the index in one go. That move is called a merge. Searches read the pending list as well as the index, so new text is found as soon as it is written, merged or not.
237
-
238
- PostgreSQL merges the list when it grows past the index's `gin_pending_list_limit`, and the write that pushes it past the limit does the whole merge itself, so that write is slow now and then. Atomic keeps such merges rare:
239
-
240
- - **A large limit.** Atomic gives the index a limit of 64 MB, instead of PostgreSQL's default of 4 MB, so a write almost never reaches it.
241
- - **Merges in the background.** Each agent process, after it has written about 128,000 characters of search text, merges the list on a connection of its own with PostgreSQL's `gin_clean_pending_list`. Nothing waits for it. Only one merge runs at a time across all agents, so the list stays at about 1 MB however many agents write.
242
- - **Autovacuum merges too.** A vacuum of the table also merges the list. Atomic has the table behind the index, `atomic.session_search_entries`, vacuumed after every 1,000 new rows.
235
+ Atomic indexes session history text with a GIN trigram index (`atomic.session_search_trgm` on `atomic.session_search_entries`). New writes land in the GIN pending list (immediately searchable) and merge in bulk.
243
236
 
244
- `atomic storage migrate`, run as the owner role, sets the limit and the autovacuum settings. You do not set them yourself. If you set a 1 MB limit, as an earlier version of this guide suggested, `atomic storage migrate` replaces it with 64 MB.
237
+ `atomic storage migrate` sets `gin_pending_list_limit` to **64 MB** (replacing PostgreSQL's 4 MB default or any previous 1 MB limit) so foreground writes rarely trigger an inline merge, and configures autovacuum on `atomic.session_search_entries` to run after every **1,000** inserted rows so pending entries flush regularly. Agents connecting as the index owner also clean the pending list asynchronously in the background; agents connecting as the least-privilege `atomic_runtime` role rely on autovacuum to perform those merges—so **keep autovacuum enabled**. Search indexing does not hold session write locks.
245
238
 
246
- Only the index's owner may run `gin_clean_pending_list`. Agents that connect as the runtime role leave the merges to autovacuum, so keep autovacuum on. Without either, the list grows to 64 MB, and the write that crosses that limit merges all of it.
239
+ <Warning>
240
+ Leave `fastupdate = on` on `atomic.session_search_trgm`. Turning `fastupdate` off forces every write straight into the GIN tree and slows search indexing dramatically.
241
+ </Warning>
247
242
 
248
- Writes to the search index don't hold the lock of the session they index, so an agent keeps saving to a session while a history search indexes it.
249
-
250
- Check the settings with:
243
+ Verify the index and table storage parameters:
251
244
 
252
245
  ```sql
253
246
  SELECT relname, reloptions
@@ -255,83 +248,67 @@ FROM pg_class
255
248
  WHERE relname IN ('session_search_trgm', 'session_search_entries');
256
249
  ```
257
250
 
258
- To see how much text waits in the pending list, use the `pgstattuple` extension. Creating it needs a superuser, or the administrator role on a managed service. Each page is 8 kB:
251
+ Inspect pending-list size (each page is 8 KB; creating `pgstattuple` requires a superuser or managed-service admin):
259
252
 
260
253
  ```sql
261
254
  CREATE EXTENSION IF NOT EXISTS pgstattuple;
262
255
  SELECT pending_pages, pending_tuples FROM pgstatginindex('atomic.session_search_trgm');
263
256
  ```
264
257
 
265
- Leave the index's `fastupdate` on. Turning it off skips the pending list and adds every entry to the index as it is written, which makes writing search text many times slower.
266
-
267
258
  ### Intercom's wake-up notices
268
259
 
269
- When one Intercom broker sends a message to another, it also writes a short notice to `atomic.intercom_wakeups` so the other broker checks for the message at once. Atomic makes this table unlogged: PostgreSQL does not write its rows to the write-ahead log, so a notice writes less and needs no disk flush when it commits.
260
+ When a broker sends a cross-host message, it writes a short wake-up hint to `atomic.intercom_wakeups` alongside the durable message in `atomic.intercom_outbox`. Atomic marks `intercom_wakeups` as `UNLOGGED` (either on creation or during `atomic storage migrate`) to eliminate WAL writes and disk flushes for ephemeral hints.
270
261
 
271
- An unlogged table is emptied when the server crashes, and it is not copied to standby servers, so it is empty after a failover. Only notices are lost. Brokers also check for messages every 30 seconds, so every message still arrives, at worst that much later. Tables created by `atomic storage migrate` or by a broker start out unlogged. A table an earlier version created becomes unlogged the next time `atomic storage migrate` runs as the owner role.
262
+ Normally, brokers receive `LISTEN/NOTIFY` notifications immediately and poll `intercom_wakeups` every **5 seconds** (or every **0.5 seconds** if `LISTEN/NOTIFY` is unavailable; see [Wake-ups](/storage/postgres#wake-ups)). If PostgreSQL crashes or fails over to a standby, the unlogged `intercom_wakeups` table empties—losing only hints while messages remain safely in `intercom_outbox`. Independently of wake-up hints, every broker scans `intercom_outbox` directly every **30 seconds** as a backup safety net, so every message still arrives within at most 30 seconds.
272
263
 
273
264
  ## Compression of large values
274
265
 
275
- PostgreSQL compresses large values, such as long session entries, stored files and Intercom messages, before it stores them. Its default method, `pglz`, is slow. `atomic storage migrate` switches those columns to `lz4` when the server supports it. Most PostgreSQL 14 and later servers do, including the PostgreSQL project's packages and Docker images.
266
+ `atomic storage migrate` automatically switches large text, JSON, and binary columns (`session_entries`, chunk tables, snapshot blobs, chat records, and `intercom_outbox`) from PostgreSQL's default `pglz` compression to **`lz4`** whenever the server supports it (standard in most PostgreSQL 14+ builds).
276
267
 
277
- `lz4` compresses and decompresses faster than `pglz`, and stores session entries in a little less space.
268
+ `lz4` compresses and decompresses roughly 2–4× faster than `pglz`—especially on already-compressed content like images and archives—for only a few percent more disk space on plain text, while avoiding the ~2× storage overhead of disabling compression (`SET STORAGE EXTERNAL`). Existing rows remain readable as-is; new writes use `lz4`. If your server was compiled without `lz4`, `migrate` reports this and leaves columns unchanged.
278
269
 
279
- Stored files and large tool outputs also use `lz4`, even though they take a little more space than with `pglz`. In tests with real data:
280
-
281
- | Data | Space with `lz4` | Time to store | Time to read |
282
- | --- | --- | --- | --- |
283
- | Large tool outputs from real sessions, 24 MB | 4% more than `pglz` | about a third of `pglz`'s | about 40% of `pglz`'s |
284
- | Tracked files of six real repositories, images included, 150 MB | 7% more than `pglz` | about 40% of `pglz`'s | about half of `pglz`'s |
285
- | Images and gzip archives, 37 MB | 3% less than `pglz` | about a quarter of `pglz`'s | the same |
286
-
287
- The extra space comes from text, which `pglz` packs slightly tighter. Data that is already compressed, such as images and archives, is where `lz4` saves the most time: `pglz` spends that time trying to compress it and failing. Storing these columns without compression (`SET STORAGE EXTERNAL`) saves no time over `lz4` and takes about twice the space on a typical mix of files.
288
-
289
- Only values written after the change use `lz4`. Values already stored stay readable as they are. To see how a table's values are compressed, run:
270
+ Check active compression methods on `session_entries` (`NULL` means a value was small enough to store inline uncompressed):
290
271
 
291
272
  ```sql
292
273
  SELECT pg_column_compression(entry_json) AS method, count(*)
293
274
  FROM atomic.session_entries GROUP BY 1;
294
275
  ```
295
276
 
296
- `NULL` is a value too small to compress. If your server was built without `lz4`, migrate says so and leaves the columns as they are.
297
-
298
277
  ## Settings you can usually leave alone
299
278
 
300
- These settings come up in tuning advice, but rarely help Atomic:
301
-
302
- - **`synchronous_commit`.** Keep it `on`. Turning it off for the whole server can lose the last commits in a crash, and on a fast disk a commit's write takes far less time than a network round trip. Atomic already turns it off for its own heartbeat writes, the lease renewals Intercom brokers send every 10 seconds, because losing one in a crash does no harm: the next renewal repeats it. Session entries, messages and every other write still wait for the disk.
303
- - **`wal_compression`.** Keep the current value. It trades a little CPU for a smaller write-ahead log.
304
- - **`deadlock_timeout`.** Atomic's lock waits are expected and end at its own lock timeout, so lowering it only adds work. Keep `log_lock_waits = on` to see long waits in the log.
279
+ - **`synchronous_commit`:** Keep `on` server-wide so crashes cannot drop committed session entries or messages. Atomic already sets `synchronous_commit = off` per transaction for repeatable broker lease heartbeats (every 10 seconds), where losing one write is harmless.
280
+ - **`wal_compression`:** Keep your server default.
281
+ - **`deadlock_timeout`:** Leave at default; Atomic's expected lock waits use its own timeouts. Keeping `log_lock_waits = on` is helpful for diagnosing long waits.
305
282
 
306
283
  ## After you upgrade Atomic
307
284
 
308
- After every Atomic upgrade, run `atomic storage migrate` once, as the owner role, before you start many agents:
285
+ Run `atomic storage migrate` once as the owner role after every Atomic upgrade, before launching your agent fleet:
309
286
 
310
287
  ```bash
311
288
  atomic storage migrate --db 'postgresql://atomic_owner@db.example.com:5432/atomic' --password-file ~/atomic-owner-password
312
289
  ```
313
290
 
314
- Why it matters for performance:
291
+ Running `migrate` as the owner role ensures:
315
292
 
316
- - **Fast starts.** An agent opens an up-to-date database in a few round trips, without taking locks. On a database that is behind, each agent starts by checking and updating it, and many agents starting at once queue behind each other.
317
- - **Changes only the owner can make.** The runtime role cannot change the schema, so `atomic storage migrate` applies the rest: `fillfactor` and autovacuum settings on the busy tables, `lz4` compression for large values, the search index settings, an unlogged table for Intercom's wake-up notices, and saving entries to a session with one wait for the server instead of two. Until it runs, agents keep working without those gains. Running agents pick them up the next time they start.
293
+ - **Fast startup:** Agents open an up-to-date database in a couple of round trips with no schema-init contention.
294
+ - **Owner-only optimizations and lazy objects:** Applies `fillfactor`, autovacuum thresholds, `lz4` compression, search index tuning, unlogged `intercom_wakeups`, the concurrent `snapshot_session_links_anchored` index rebuild (up to a 6-hour statement timeout for large tables without blocking writes), the single-round-trip session append function, and lazily initialized tables (fork staging, chat records, Intercom ended-child queue). Each table tuning `ALTER TABLE` uses a 2-second `lock_timeout` and gracefully skips busy tables without failing the migration—re-run later if any table was skipped.
318
295
 
319
296
  ## Checklist
320
297
 
321
- | Step | Restart needed |
298
+ | Step | Restart required |
322
299
  | --- | --- |
323
- | Run the database in the same region as the agents | No |
324
- | Size `max_connections` and per-role limits from the connection count, or put PgBouncer in front | `max_connections` only |
325
- | Set `shared_buffers` to about a quarter of memory | Yes |
326
- | Reserve huge pages with `vm.nr_hugepages` and check `huge_pages_status` | Yes |
327
- | Preload `pg_stat_statements`, create it as a superuser, grant `pg_read_all_stats` | Yes |
328
- | Run `atomic storage migrate` after each Atomic upgrade | No |
329
- | Keep autovacuum on, so it merges the search index's pending list for agents that use a runtime role | No |
300
+ | Run PostgreSQL in the same region (ideally same zone) as your agents | No |
301
+ | Size `max_connections` and `atomic_runtime` `CONNECTION LIMIT`, or deploy PgBouncer | `max_connections` only |
302
+ | Set `shared_buffers` to ~25% of host RAM | Yes |
303
+ | Reserve Linux huge pages (`vm.nr_hugepages`) and verify `huge_pages_status` | Yes |
304
+ | Preload and create `pg_stat_statements`; grant `pg_read_all_stats` | Yes |
305
+ | Run `atomic storage migrate` as owner after every Atomic upgrade | No |
306
+ | Keep autovacuum enabled so search pending lists merge under runtime roles | No |
330
307
 
331
- On a managed service, such as Amazon RDS, Azure Database for PostgreSQL or Google Cloud SQL, the server settings above may be fixed or set through the service's own parameters. The SQL statements work the same way there, except that creating `pg_stat_statements` needs the service's administrator role.
308
+ On managed services (Amazon RDS, Azure Database for PostgreSQL, Google Cloud SQL), adjust server settings through parameter groups or console controls; SQL statements work identically (creating extensions requires the managed admin role).
332
309
 
333
310
  ## Related pages
334
311
 
335
- - [PostgreSQL setup](/storage/postgres): set up the database and roles.
336
- - [Tuning for many concurrent agents](/storage/postgres#tuning-for-many-concurrent-agents): size Atomic's connection settings.
337
- - [Run many agents on PostgreSQL with PgBouncer](/storage/postgres/pgbouncer).
312
+ - [PostgreSQL setup](/storage/postgres): database roles, TLS, proxies, and troubleshooting.
313
+ - [Tuning for many concurrent agents](/storage/postgres#tuning-for-many-concurrent-agents): client pool arithmetic and `maxConnections`.
314
+ - [Use PgBouncer with PostgreSQL](/storage/postgres/pgbouncer): transaction pooling configuration and health checks.