influxdata/influxdb · error · anyhow::Error

database not found for trigger

Error message

database not found for trigger {key:?}

What it means

Raised by `plugin_for_key` when the catalog has no database schema for the `db_id` stored in the trigger key. The trigger references a database that no longer exists (or has not been loaded into this node's catalog), so the plugin cannot be resolved.

Solutions

  1. Drop or recreate the orphaned trigger: `DROP TRIGGER <name>` (or recreate the missing database).
  2. Verify the database exists with `SHOW DATABASES` and that the trigger's DB name is spelled correctly.
  3. Restart/re-sync so the catalog is fully loaded on this node.
  4. In tests, build the TriggerKey from an actual catalog lookup rather than hand-constructed IDs.

Example fix

// before (fabricated key in test)
let key = TriggerKey { db_id: DatabaseId::new(), trigger_id: TriggerId::new() };
// after
let db = catalog.db_schema("mydb").unwrap();
let trig = db.processing_engine_triggers.get_by_name("my_trigger").unwrap();
let key = TriggerKey { db_id: db.id, trigger_id: trig.id };
Defensive patterns

Strategy: validation

Validate before calling

// Resolve the key from a live catalog instead of constructing IDs by hand
let db_schema = catalog.db_schema_by_id(&key.db_id)
    .ok_or_else(|| anyhow!("db {} missing; drop orphaned trigger", key.db_id))?;

Try / catch

// Caller
match worker.load_plugin_for_test(key) {
    Err(e) if e.to_string().contains("database not found for trigger") => {
        // recover: drop the orphaned trigger or recreate the database, then retry
    }
    other => other?,
}

Prevention

When it happens

Trigger: `execute_once` (scheduled/WAL trigger run) or `load_plugin_for_test` with a `TriggerKey` whose `db_id` is absent from `self.catalog.db_schema_by_id` — typically after the database was dropped while the trigger still exists, or a stale key from a pre-restart catalog.

Common situations: Deleting a database with an active trigger and the trigger record lingering; restoring/partial catalog load where triggers survived but the DB didn't; test harness passing a fabricated TriggerKey.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of influxdata/influxdb@06200ef96b (2026-09-19). Data as JSON: /api/errors/a406baba45a89b8e. Report an issue: GitHub.

Appendix: source

Thrown at influxdb3_processing_engine/src/worker/local.rs:188

    }

    fn scheduler_for(&self, scheduler_node_id: &str) -> Option<Arc<dyn TriggerScheduler>> {
        let mut schedulers = self.schedulers.lock();
        let scheduler = schedulers.get(scheduler_node_id).and_then(Weak::upgrade);
        if scheduler.is_none() {
            schedulers.remove(scheduler_node_id);
        }
        scheduler
    }

    async fn plugin_for_key(
        &self,
        key: TriggerKey,
    ) -> Result<Arc<TriggerPlugin>, TriggerExecutionError> {
        let db_schema = self
            .catalog
            .db_schema_by_id(&key.db_id)
            .ok_or_else(|| anyhow!("database not found for trigger {key:?}"))?;
        let trigger_definition = db_schema
            .processing_engine_triggers
            .get_by_id(&key.trigger_id)
            .ok_or_else(|| anyhow!("trigger not found: {key:?}"))?;
        let db_name = db_schema.name.to_string();

        let load_generation = {
            let mut plugins = self.plugins.lock();
            let slot = plugins.entry(key).or_insert_with(|| self.new_plugin_slot());
            if let Some(plugin) = &slot.plugin
                && plugin.matches(&db_name, &trigger_definition)
            {
                return Ok(Arc::clone(plugin));
            }
            slot.generation
        };

        let plugin_code = Arc::new(

View on GitHub (pinned to 06200ef96b)