Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ 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
working-directory: packages/db
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'
Expand Down Expand Up @@ -386,6 +391,11 @@ 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
working-directory: packages/db
run: bun scripts/tune-ci-postgres.ts

- name: Provision the database through migrations
working-directory: packages/db
run: bun run db:migrate
Expand Down Expand Up @@ -505,6 +515,11 @@ 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
working-directory: packages/db
run: bun scripts/tune-ci-postgres.ts

- name: Provision the database through migrations
working-directory: packages/db
run: bun run db:migrate
Expand Down
43 changes: 43 additions & 0 deletions packages/db/scripts/tune-ci-postgres.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* 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 (from packages/db): DATABASE_URL=... bun scripts/tune-ci-postgres.ts
*/
import postgres from 'postgres'

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')

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<string, string> = {}
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)
Loading