From 377decaf3df99885646ef4ad44db1c29e7e362aa Mon Sep 17 00:00:00 2001 From: Daan Meijer Date: Wed, 14 Oct 2026 16:27:58 +0200 Subject: [PATCH] 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 --- ...1770000003100_chunk_indexes_with_chunks.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 database/migrations/1770000003100_chunk_indexes_with_chunks.ts diff --git a/database/migrations/1770000003100_chunk_indexes_with_chunks.ts b/database/migrations/1770000003100_chunk_indexes_with_chunks.ts new file mode 100644 index 0000000..f453a35 --- /dev/null +++ b/database/migrations/1770000003100_chunk_indexes_with_chunks.ts @@ -0,0 +1,26 @@ +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() {} +}