Skip to content

Commit 74eca43

Browse files
authored
improvement(ci): turn off crash durability on throwaway CI postgres (#10251)
* improvement(ci): turn off crash durability on throwaway CI postgres * fix(ci): keep synchronous_commit on and scope durability tuning to e2e jobs
1 parent 126da70 commit 74eca43

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

‎.github/workflows/checks.yml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ jobs:
265265
with:
266266
provider: github
267267

268+
# No suite survives a database crash; see the script for what this does and does not change.
269+
- name: Turn off Postgres crash durability
270+
working-directory: packages/db
271+
run: bun scripts/tune-ci-postgres.ts
272+
268273
# Migrations create their own extensions, as on a fresh self-hosted install.
269274
- name: Provision the database through migrations
270275
if: matrix.group != 'project-files'
@@ -386,6 +391,11 @@ jobs:
386391
with:
387392
provider: ${{ vars.CI_PROVIDER }}
388393

394+
# No suite survives a database crash; see the script for what this does and does not change.
395+
- name: Turn off Postgres crash durability
396+
working-directory: packages/db
397+
run: bun scripts/tune-ci-postgres.ts
398+
389399
- name: Provision the database through migrations
390400
working-directory: packages/db
391401
run: bun run db:migrate
@@ -505,6 +515,11 @@ jobs:
505515
with:
506516
provider: ${{ vars.CI_PROVIDER }}
507517

518+
# No suite survives a database crash; see the script for what this does and does not change.
519+
- name: Turn off Postgres crash durability
520+
working-directory: packages/db
521+
run: bun scripts/tune-ci-postgres.ts
522+
508523
- name: Provision the database through migrations
509524
working-directory: packages/db
510525
run: bun run db:migrate
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Turns off crash durability on a CI job's throwaway Postgres service. No suite survives a crash of
3+
* its database, and flushing each commit to the runner's disk is most of a bulk write's cost.
4+
* Visibility, locking and isolation are unchanged, so every suite checks the same behavior.
5+
* `synchronous_commit` stays on: asynchronous commits delay hint bits and VACUUM's all-visible
6+
* marking until the WAL flush, which turns the index-only plans the plan tests assert into heap
7+
* fetches. With `fsync` off that flush costs nothing anyway.
8+
*
9+
* Service containers take no `-c` flags; each setting reloads without a restart. Exits non-zero
10+
* unless a fresh session reports all of them applied.
11+
*
12+
* Usage (from packages/db): DATABASE_URL=... bun scripts/tune-ci-postgres.ts
13+
*/
14+
import postgres from 'postgres'
15+
16+
const SETTINGS = { fsync: 'off', full_page_writes: 'off' } as const
17+
18+
const url = process.env.DATABASE_URL
19+
if (!url) throw new Error('DATABASE_URL is required')
20+
21+
const admin = postgres(url, { max: 1, onnotice: () => {} })
22+
for (const [name, value] of Object.entries(SETTINGS)) {
23+
await admin.unsafe(`ALTER SYSTEM SET ${name} = ${value}`)
24+
}
25+
await admin`SELECT pg_reload_conf()`
26+
await admin.end()
27+
28+
let applied: Record<string, string> = {}
29+
for (let attempt = 0; attempt < 10; attempt++) {
30+
// pg_reload_conf only signals the server, so read from a new session until it has reloaded.
31+
const probe = postgres(url, { max: 1 })
32+
const rows = await probe<{ name: string; setting: string }[]>`
33+
SELECT name, setting FROM pg_settings WHERE name IN ${probe(Object.keys(SETTINGS))}`
34+
await probe.end()
35+
applied = Object.fromEntries(rows.map((row) => [row.name, row.setting]))
36+
if (Object.entries(SETTINGS).every(([name, value]) => applied[name] === value)) {
37+
console.log('Postgres durability off:', applied)
38+
process.exit(0)
39+
}
40+
await Bun.sleep(500)
41+
}
42+
console.error('::error::Postgres did not apply the CI durability settings:', applied)
43+
process.exit(1)

0 commit comments

Comments
 (0)