Home / Databricks on Azure

Databricks on AzureRunbookAdvanced

Sev1: all Unity Catalog catalogs disappeared from a workspace because the metastore was unassigned

Every job and query fails with TABLE_OR_VIEW_NOT_FOUND or "no metastore assigned" and only hive_metastore is visible. Confirm the metastore assignment was removed, reassign it, and lock the assignment down.

Deepak Bhardwaj5 min read

Applies toAzure Databricks Unity Catalog, Databricks CLI 0.205+, Terraform databricks provider (databricks_metastore_assignment)

Symptoms

  • All users in one workspace lose every Unity Catalog catalog at the same time. Catalog Explorer shows only hive_metastore (or nothing).
  • Jobs and dashboards fail with TABLE_OR_VIEW_NOT_FOUND, [NO_SUCH_CATALOG_EXCEPTION] or a message that no metastore is assigned to the workspace.
  • SELECT current_metastore() fails or returns nothing.
  • Other workspaces on the same metastore are fine.
  • Started after a Terraform apply or destroy, a workspace migration, or account console work.

This is usually a metastore assignment problem, not data loss. The metastore, its catalogs, grants and data still exist at account level. The workspace just isn't attached to them.

Caution

Do not create a new metastore for the workspace to "get things working". Azure Databricks allows one metastore per region, and a new metastore would have none of your catalogs, grants or managed tables. Reassign the existing metastore.

1. Confirm scope and impact (5 minutes)

From a notebook or SQL warehouse in the affected workspace:

SELECT current_metastore();
SHOW CATALOGS;

From the CLI, using a profile for the affected workspace:

databricks metastores current -p prod
databricks metastores summary -p prod

If current returns an error saying no metastore is assigned, the assignment is gone. Then check from a healthy workspace on the same region that the metastore itself still exists:

databricks metastores list -p healthy-ws -o json | jq '.[] | {name, metastore_id, region}'
Finding Meaning
Metastore exists, affected workspace has no assignment Reassign it (step 3). Most common case.
Affected workspace is assigned to a different metastore Someone reassigned it. Reassign back (step 3).
Metastore missing from the list everywhere The metastore was deleted. Open a Sev A ticket with Databricks support right away. Don't recreate it.
Assignment fine but catalogs missing Workspace-catalog bindings or grants changed, not the assignment. See catalog not visible in a workspace.

Note the workspace ID (the number after adb- in the workspace URL, or az databricks workspace show --query workspaceId).

2. Find what removed it

Account-level audit events are logged with an empty or null workspace ID. In a healthy workspace with system tables enabled:

SELECT event_time, user_identity.email, action_name, request_params, response.status_code
FROM system.access.audit
WHERE service_name = 'unityCatalog'
  AND action_name ILIKE '%metastoreassignment%'
  AND event_time > now() - INTERVAL 3 DAYS
ORDER BY event_time DESC;

Action names vary by API version (for example create, update and delete metastore assignment). The ILIKE filter catches them. If the caller was a Terraform service principal, find the pipeline run and pause it before you fix anything. Otherwise the next apply removes the assignment again.

Typical causes:

  • A Terraform module refactor dropped or renamed the databricks_metastore_assignment resource, so the plan showed it as destroyed.
  • terraform destroy run against the wrong state or workspace.
  • A workspace was reassigned while someone was testing a new metastore.

3. Reassign the metastore

You need to be an account admin. The CLI call takes the workspace ID, metastore ID and a default catalog name:

databricks metastores assign <workspace-id> <metastore-id> main -p prod

If the workspace is currently attached to the wrong metastore, assign overwrites the existing assignment. update-assignment changes an assignment that already exists:

databricks metastores update-assignment <workspace-id> --metastore-id <metastore-id> -p prod

The default catalog argument is deprecated in favour of the workspace default namespace setting. Pass the catalog you had before (often main or the workspace catalog), then check that setting in Settings > Workspace admin > Advanced > Default catalog for the workspace.

If Terraform owns the assignment, fix it in code and apply instead, so state matches reality:

resource "databricks_metastore_assignment" "prod" {
  provider     = databricks.account
  workspace_id = var.prod_workspace_id
  metastore_id = var.metastore_id
}

If you used the CLI to fix it first, run terraform import for the assignment (format <workspace_id>|<metastore_id>) before the next apply. That way Terraform doesn't try to create a duplicate or destroy it.

4. Verify recovery

SELECT current_metastore();
SHOW CATALOGS;
SELECT count(*) FROM prod.sales.orders;
SHOW GRANTS ON CATALOG prod;

Check:

  • Catalogs with workspace bindings (ISOLATED mode) are visible again. Bindings belong to the catalog and should still list this workspace.
  • Grants are intact. They are stored in the metastore and are not removed when an assignment is removed.
  • Running clusters and SQL warehouses may cache the "no metastore" state. Restart the shared clusters and warehouses that jobs use.
  • Repair failed job runs. For streaming jobs, restart them and check they resumed from their checkpoints rather than from the beginning.
databricks jobs list-runs --completed-only --limit 100 -p prod -o json \
  | jq -r '.[] | select(.state.result_state=="FAILED") | [.job_id, .run_id, .run_name] | @tsv'

Communicate

"From HH:MM to HH:MM the prod Databricks workspace lost its connection to Unity Catalog after an automated change removed the metastore assignment. No data or permissions were lost. Jobs that failed in that window are being re-run. Dashboards that showed errors will work after refresh."

Prevent it next time

  • Manage databricks_metastore_assignment in a small, separate Terraform stack owned by the platform team, not inside per-team workspace modules.
  • Add lifecycle { prevent_destroy = true } to the assignment and to the metastore resource.
  • Gate Terraform plans: fail the pipeline if the plan destroys databricks_metastore_assignment, databricks_metastore or databricks_catalog.
  • Keep the account admin role to a few named people and one automation principal.
  • Alert on metastore assignment audit events from system.access.audit, using a scheduled SQL alert on the query in step 2.
  • Run a synthetic job every few minutes that runs SELECT current_metastore() and pages on failure.