From f8dc592dfe86ad102b02f74fa05dcd22659e02fd Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Fri, 20 Nov 2026 11:17:33 -0800 Subject: [PATCH 1/2] improvement(ci): turn off crash durability on throwaway CI postgres --- .github/workflows/checks.yml | 16 +++++++++++++++ scripts/tune-ci-postgres.ts | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 scripts/tune-ci-postgres.ts diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index ead3aff1634..7ae7e03f795 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -145,6 +145,10 @@ jobs: with: provider: ${{ vars.CI_PROVIDER }} + # No suite survives a database crash; see the script for what this does and does not change. + - name: Turn off Postgres crash durability + run: bun scripts/tune-ci-postgres.ts + - name: Provision a fresh database through the supported command working-directory: packages/db run: | @@ -265,6 +269,10 @@ jobs: with: provider: github + # No suite survives a database crash; see the script for what this does and does not change. + - name: Turn off Postgres crash durability + run: bun scripts/tune-ci-postgres.ts + # Migrations create their own extensions, as on a fresh self-hosted install. - name: Provision the database through migrations if: matrix.group != 'project-files' @@ -386,6 +394,10 @@ jobs: with: provider: ${{ vars.CI_PROVIDER }} + # No suite survives a database crash; see the script for what this does and does not change. + - name: Turn off Postgres crash durability + run: bun scripts/tune-ci-postgres.ts + - name: Provision the database through migrations working-directory: packages/db run: bun run db:migrate @@ -505,6 +517,10 @@ jobs: with: provider: ${{ vars.CI_PROVIDER }} + # No suite survives a database crash; see the script for what this does and does not change. + - name: Turn off Postgres crash durability + run: bun scripts/tune-ci-postgres.ts + - name: Provision the database through migrations working-directory: packages/db run: bun run db:migrate diff --git a/scripts/tune-ci-postgres.ts b/scripts/tune-ci-postgres.ts new file mode 100644 index 00000000000..4fe82784120 --- /dev/null +++ b/scripts/tune-ci-postgres.ts @@ -0,0 +1,40 @@ +/** + * Turns off crash durability on a CI job's throwaway Postgres service. No suite survives a crash of + * its database, and flushing each commit to the runner's disk is most of a bulk write's cost. + * Visibility, locking and isolation are unchanged, so every suite checks the same behavior. + * + * Service containers take no `-c` flags; each setting reloads without a restart. Exits non-zero + * unless a fresh session reports all of them applied. + * + * Usage: DATABASE_URL=... bun scripts/tune-ci-postgres.ts + */ +import postgres from 'postgres' + +const SETTINGS = { fsync: 'off', full_page_writes: 'off', synchronous_commit: 'off' } as const + +const url = process.env.DATABASE_URL +if (!url) throw new Error('DATABASE_URL is required') + +const admin = postgres(url, { max: 1, onnotice: () => {} }) +for (const [name, value] of Object.entries(SETTINGS)) { + await admin.unsafe(`ALTER SYSTEM SET ${name} = ${value}`) +} +await admin`SELECT pg_reload_conf()` +await admin.end() + +let applied: Record = {} +for (let attempt = 0; attempt < 10; attempt++) { + // pg_reload_conf only signals the server, so read from a new session until it has reloaded. + const probe = postgres(url, { max: 1 }) + const rows = await probe<{ name: string; setting: string }[]>` + SELECT name, setting FROM pg_settings WHERE name IN ${probe(Object.keys(SETTINGS))}` + await probe.end() + applied = Object.fromEntries(rows.map((row) => [row.name, row.setting])) + if (Object.entries(SETTINGS).every(([name, value]) => applied[name] === value)) { + console.log('Postgres durability off:', applied) + process.exit(0) + } + await Bun.sleep(500) +} +console.error('::error::Postgres did not apply the CI durability settings:', applied) +process.exit(1) From 0b0a7772511c17028f36249303b74938c6d04221 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Fri, 20 Nov 2026 11:35:10 -0800 Subject: [PATCH 2/2] fix(ci): keep synchronous_commit on and scope durability tuning to e2e jobs --- .github/workflows/checks.yml | 7 +++---- {scripts => packages/db/scripts}/tune-ci-postgres.ts | 7 +++++-- 2 files changed, 8 insertions(+), 6 deletions(-) rename {scripts => packages/db/scripts}/tune-ci-postgres.ts (79%) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 7ae7e03f795..78bb91b7f53 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -145,10 +145,6 @@ jobs: with: provider: ${{ vars.CI_PROVIDER }} - # No suite survives a database crash; see the script for what this does and does not change. - - name: Turn off Postgres crash durability - run: bun scripts/tune-ci-postgres.ts - - name: Provision a fresh database through the supported command working-directory: packages/db run: | @@ -271,6 +267,7 @@ jobs: # No suite survives a database crash; see the script for what this does and does not change. - name: Turn off Postgres crash durability + working-directory: packages/db run: bun scripts/tune-ci-postgres.ts # Migrations create their own extensions, as on a fresh self-hosted install. @@ -396,6 +393,7 @@ jobs: # No suite survives a database crash; see the script for what this does and does not change. - name: Turn off Postgres crash durability + working-directory: packages/db run: bun scripts/tune-ci-postgres.ts - name: Provision the database through migrations @@ -519,6 +517,7 @@ jobs: # No suite survives a database crash; see the script for what this does and does not change. - name: Turn off Postgres crash durability + working-directory: packages/db run: bun scripts/tune-ci-postgres.ts - name: Provision the database through migrations diff --git a/scripts/tune-ci-postgres.ts b/packages/db/scripts/tune-ci-postgres.ts similarity index 79% rename from scripts/tune-ci-postgres.ts rename to packages/db/scripts/tune-ci-postgres.ts index 4fe82784120..fcd0692fd05 100644 --- a/scripts/tune-ci-postgres.ts +++ b/packages/db/scripts/tune-ci-postgres.ts @@ -2,15 +2,18 @@ * Turns off crash durability on a CI job's throwaway Postgres service. No suite survives a crash of * its database, and flushing each commit to the runner's disk is most of a bulk write's cost. * Visibility, locking and isolation are unchanged, so every suite checks the same behavior. + * `synchronous_commit` stays on: asynchronous commits delay hint bits and VACUUM's all-visible + * marking until the WAL flush, which turns the index-only plans the plan tests assert into heap + * fetches. With `fsync` off that flush costs nothing anyway. * * Service containers take no `-c` flags; each setting reloads without a restart. Exits non-zero * unless a fresh session reports all of them applied. * - * Usage: DATABASE_URL=... bun scripts/tune-ci-postgres.ts + * Usage (from packages/db): DATABASE_URL=... bun scripts/tune-ci-postgres.ts */ import postgres from 'postgres' -const SETTINGS = { fsync: 'off', full_page_writes: 'off', synchronous_commit: 'off' } as const +const SETTINGS = { fsync: 'off', full_page_writes: 'off' } as const const url = process.env.DATABASE_URL if (!url) throw new Error('DATABASE_URL is required')