Files
usenet-indexer/database/migrations/1770000003100_chunk_indexes_with_chunks.ts
T
Daan MeijerandClaude Opus 5.5 377decaf3d
Test and deploy / test (push) Successful in 53s
Test and deploy / edge (push) Successful in 2m8s
Test and deploy / deploy (push) Successful in 2m7s
release_chunks' indexes with its chunks (CHUNK_TABLESPACE)
The October partition's three indexes took 2.9 GB of the NVMe, its pkey
never scanned; chunks are read from the HDD anyway. Moved on homelab by hand
(12 s); the migration does the same on a new deploy, parent indexes too so new
partitions follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 16:27:58 +02:00

27 lines
1.1 KiB
TypeScript

import { BaseSchema } from '@adonisjs/lucid/schema'
import env from '#start/env'
/**
* release_chunks' indexes with its chunks in CHUNK_TABLESPACE (the HDD), not the catalog's tablespace: a chunk is
* read from the HDD anyway, and the October partition's three indexes took 2.9 GB of the NVMe (its pkey never
* scanned; LOG.md 2026-10-14 (54)). The parent's partitioned indexes too, so new partitions put theirs there.
* Homelab was moved by hand first; a no-op where they're there already.
*/
export default class extends BaseSchema {
async up() {
const tablespace = env.get('CHUNK_TABLESPACE')
if (!tablespace) return
this.defer(async (db) => {
const { rows } = await db.rawQuery(
`SELECT i.relname FROM pg_class c JOIN pg_index x ON x.indrelid = c.oid JOIN pg_class i ON i.oid = x.indexrelid
LEFT JOIN pg_tablespace t ON t.oid = i.reltablespace
WHERE c.relname LIKE 'release_chunks%' AND coalesce(t.spcname, 'pg_default') <> ?`,
[tablespace]
)
for (const { relname } of rows) await db.rawQuery(`ALTER INDEX ${relname} SET TABLESPACE ${tablespace}`)
})
}
async down() {}
}