diegosouzapw/OmniRoute · error

[DB] Failed to restore WAL mode after optimization settings

Error message

[DB] Failed to restore WAL mode after optimization settings: ${message}

What it means

After applying persistent optimization pragmas (auto_vacuum, page_size + VACUUM, temporarily switching journal_mode to DELETE), restoring journal_mode = WAL failed in the finally block. The new page/auto_vacuum settings were applied, but the database may be left in DELETE journal mode, which degrades concurrent write performance until WAL is restored.

Solutions

  1. Manually run PRAGMA journal_mode = WAL on the database
  2. Check for connections/locks preventing the journal-mode switch
  3. Restart the server so startup re-applies WAL mode
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at src/lib/db/optimizationSettings.ts:208 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/a802ce5d765611c4. Report an issue: GitHub.

Appendix: source

Thrown at src/lib/db/optimizationSettings.ts:208

  console.log(
    `[DB] Applying persistent optimization settings ` +
      `(auto_vacuum ${currentAutoVacuum}->${targetAutoVacuum}, ` +
      `page_size ${currentPageSize}->${targetPageSize})`
  );

  try {
    if (shouldRestoreWal) db.pragma("journal_mode = DELETE");
    db.pragma(`auto_vacuum = ${targetAutoVacuum}`);
    db.pragma(`page_size = ${targetPageSize}`);
    db.exec("VACUUM");
  } finally {
    if (shouldRestoreWal) {
      try {
        db.pragma("journal_mode = WAL");
      } catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        console.warn(`[DB] Failed to restore WAL mode after optimization settings: ${message}`);
      }
    }
  }

  const newAutoVacuum = db.pragma("auto_vacuum", { simple: true }) as number;
  const newPageSize = db.pragma("page_size", { simple: true }) as number;
  if (newAutoVacuum !== targetAutoVacuum || newPageSize !== targetPageSize) {
    throw new Error(
      `database optimization settings did not take effect ` +
        `(auto_vacuum expected ${targetAutoVacuum}, got ${newAutoVacuum}; ` +
        `page_size expected ${targetPageSize}, got ${newPageSize})`
    );
  }
}

export function applyDatabaseOptimizationSettingsForDb(
  db: SqliteDatabase,
  settings: DatabaseOptimizationSettings,

View on GitHub (pinned to a179ffed5b)