diff --git a/database/migrations/1770000004500_probe_cache_pkey_on_nvme.ts b/database/migrations/1770000004500_probe_cache_pkey_on_nvme.ts new file mode 100644 index 0000000..b897de8 --- /dev/null +++ b/database/migrations/1770000004500_probe_cache_pkey_on_nvme.ts @@ -0,0 +1,26 @@ +import { BaseSchema } from '@adonisjs/lucid/schema' + +/** + * probe_cache's primary key in the catalog's tablespace (default_tablespace: nvme on homelab); the table stays on the + * HDD. Each claim looks its candidates up by message_id (`message_id = ANY(…)`): with the index on the HDD that took + * 1.27 s a claim, 48 s of each minute, the prober's lanes waiting on claims (LOG.md 2026-10-18 (76)). ~97% aren't in it, + * so only the index is read. Homelab moved it by hand (prober stopped); a no-op where it's there already, or without a + * default tablespace (tests). + */ +export default class extends BaseSchema { + async up() { + this.defer(async (db) => { + const { rows: setting } = await db.rawQuery(`SELECT current_setting('default_tablespace') AS target`) + const target = setting[0].target + if (!target) return + const { rows } = await db.rawQuery( + `SELECT 1 FROM pg_class c LEFT JOIN pg_tablespace t ON t.oid = c.reltablespace + WHERE c.relname = 'probe_cache_pkey' AND coalesce(t.spcname, 'pg_default') <> ?`, + [target] + ) + if (rows.length > 0) await db.rawQuery(`ALTER INDEX probe_cache_pkey SET TABLESPACE ${target}`) + }) + } + + async down() {} +}