From c65282ec5dc61f9ba9c866c47b975cb929705b3d Mon Sep 17 00:00:00 2001 From: Daan Meijer Date: Wed, 14 Oct 2026 23:11:36 +0200 Subject: [PATCH] par2_files, fragments and probe_cache with the chunks (CHUNK_TABLESPACE) ~20 GB of the NVMe, read by key only; the catalog was at its cap and history paused. Moved on homelab by hand (3 min, writers stopped; the cap raised to 100); the migration does the same on a new deploy. Co-Authored-By: Claude Opus 5.5 --- ...00003200_rarely_read_tables_with_chunks.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 database/migrations/1770000003200_rarely_read_tables_with_chunks.ts diff --git a/database/migrations/1770000003200_rarely_read_tables_with_chunks.ts b/database/migrations/1770000003200_rarely_read_tables_with_chunks.ts new file mode 100644 index 0000000..21ac489 --- /dev/null +++ b/database/migrations/1770000003200_rarely_read_tables_with_chunks.ts @@ -0,0 +1,32 @@ +import { BaseSchema } from '@adonisjs/lucid/schema' +import env from '#start/env' + +/** + * par2_files, fragments and probe_cache, with their indexes, in CHUNK_TABLESPACE (the HDD): ~20 GB of the NVMe at + * 42M releases, read by key only (the merger, the fragment merger, the prober). The catalog was at its + * CATALOG_MAX_NVME_GB cap and history paused (LOG.md 2026-10-14 (55)). Homelab was moved by hand first (3 min, + * with the writers stopped); a no-op where they're there already. + */ +const TABLES = ['par2_files', 'fragments', 'probe_cache'] + +export default class extends BaseSchema { + async up() { + const tablespace = env.get('CHUNK_TABLESPACE') + if (!tablespace) return + this.defer(async (db) => { + for (const table of TABLES) { + const { rows } = await db.rawQuery( + `SELECT c.relname, c.relkind FROM pg_class c LEFT JOIN pg_tablespace t ON t.oid = c.reltablespace + WHERE (c.relname = ? OR c.oid IN (SELECT indexrelid FROM pg_index WHERE indrelid = ?::regclass)) + AND coalesce(t.spcname, 'pg_default') <> ?`, + [table, table, tablespace] + ) + for (const { relname, relkind } of rows) { + await db.rawQuery(`ALTER ${relkind === 'i' ? 'INDEX' : 'TABLE'} ${relname} SET TABLESPACE ${tablespace}`) + } + } + }) + } + + async down() {} +}