{"record":{"id":"2a71627ef2f76b9e","repo":"clockworklabs/SpacetimeDB","slug":"mismatched-database-identity","errorCode":null,"errorMessage":"mismatched database identity: {} != {}","messagePattern":"mismatched database identity: (.+?) != (.+?)","errorType":"exception","errorClass":"DBError","httpStatus":null,"severity":"critical","filePath":"crates/engine/src/relational_db.rs","lineNumber":344,"sourceCode":"\n        let elapsed_time = start_time.elapsed();\n        ENGINE_METRICS\n            .replay_total_time_seconds\n            .with_label_values(&database_identity)\n            .set(elapsed_time.as_secs_f64());\n\n        let db = Self::new(\n            database_identity,\n            owner_identity,\n            inner,\n            persistence,\n            metrics_recorder_queue,\n        );\n        db.migrate_system_tables()?;\n\n        if let Some(meta) = db.metadata()? {\n            if meta.database_identity != database_identity {\n                return Err(anyhow!(\n                    \"mismatched database identity: {} != {}\",\n                    meta.database_identity,\n                    database_identity\n                )\n                .into());\n            }\n            if meta.owner_identity != owner_identity {\n                return Err(anyhow!(\n                    \"mismatched owner identity: {} != {}\",\n                    meta.owner_identity,\n                    owner_identity\n                )\n                .into());\n            }\n        };\n        let connected_clients = db.connected_clients()?;\n\n        Ok((db, connected_clients))","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/3653d2ed498fddbd83b7062aa6bf8970e18635ec/crates/engine/src/relational_db.rs#L326-L362","documentation":"RelationalDB::open cross-checks the database identity recorded in the database's persisted metadata (st_module) against the database_identity argument. The error means the commitlog/snapshot being opened belongs to a different database than the identity you passed.","triggerScenarios":"Opening a commitlog directory or snapshot repository of database A while passing database B's identity; a host routing bug that substitutes the requester's or owner's identity for the database identity; re-using an old data-dir after the database was deleted and recreated with a new identity.","commonSituations":"Wrong --data-dir / database directory mapping; snapshot files restored into another database's directory; host configuration mixing up identities after database re-creation.","solutions":["Point the open at the data directory / commitlog that belongs to the passed database_identity","If the directory is the intended one, pass the identity recorded in the persisted metadata instead of the configured one","If the on-disk database is stale and its data is disposable, wipe the directory and let it be recreated under the new identity"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Pre-check the snapshot repository's identity before opening\nif let Some(repo) = persistence.as_ref().and_then(|p| p.snapshot_repo()) {\n    anyhow::ensure!(\n        repo.database_identity() == database_identity,\n        \"data directory belongs to {}\", repo.database_identity()\n    );\n}\nlet (db, clients) = RelationalDB::open(database_identity, owner_identity, history, persistence, queue, pool)?;","typeGuard":"fn identities_match(a: Identity, b: Identity) -> bool { a == b }","tryCatchPattern":"match RelationalDB::open(database_identity, owner_identity, history, persistence, queue, pool) {\n    Err(e) if e.to_string().starts_with(\"mismatched database identity\") => {\n        // operator error: wrong data-dir; do not retry with the same arguments\n        panic::abort_open_and_alert_operator(e);\n    }\n    r => r,\n}","preventionTips":["Bind database_identity to the data directory at creation and store the mapping durably","Verify snapshot repo identity before open (it is exposed on the repo)","Never copy database directories between identities; recreate instead"],"tags":["rust","spacetimedb","database","identity","data-integrity","startup"],"backgroundTag":"database-identity-mismatch","analyzedSha":"3653d2ed498fddbd83b7062aa6bf8970e18635ec","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}