Sub topic 3
Attaching a metastore to workspaces
This chapter assumes you know what a metastore is from the previous chapter. You should also be comfortable in a Databricks workspace and know the difference between account-level and workspace-level administration. Here you will see how a metastore connects to workspaces, what the connection changes, and how to check it.
Why the attachment matters
A metastore is created at the account level. It does not belong to a workspace. Until you attach it to a workspace, users in that workspace cannot see its catalogs, schemas, or tables. The attachment is called a metastore assignment.
The assignment is what makes governance shared. Several workspaces can use the same metastore. A table created in one workspace is then visible in the others, and the same grants apply everywhere.
The rules of assignment
Four rules cover most situations:
- A workspace is assigned to at most one metastore at a time.
- One metastore can be assigned to many workspaces.
- A metastore and its workspaces must be in the same cloud region.
- An account normally has one metastore per region. Databricks recommends this layout.
The last rule drives most design decisions. If you run workspaces in two regions, you need two metastores. Objects in one metastore are not visible in the other. To share data across them, use Delta Sharing or copy the data.
Who can do the assignment
Assignment is an account-level action. You need the account admin role. A metastore admin who is not an account admin can manage objects inside the metastore but cannot attach it to a workspace.
Workspace admins cannot assign a metastore to their own workspace unless they also hold an account role that allows it. This keeps the decision about which workspaces share governed data with the account owners.
| Action | Typical role needed |
|---|---|
| Create a metastore | Account admin |
| Assign a metastore to a workspace | Account admin |
| Create catalogs in the metastore | Metastore admin, or a user granted `CREATE CATALOG` |
| Use data in the workspace | Any user granted the right privileges |
How to assign a metastore
In the account console, the steps are:
- Sign in to the account console as an account admin.
- Open the Catalog section and select the metastore.
- Open the Workspaces tab.
- Choose Assign to workspace and select one or more workspaces in the same region.
- Confirm the assignment.
You can also script the assignment through the Account API or the Databricks CLI. The CLI has an account-level metastore-assignments command group. Run databricks account metastore-assignments --help to see the exact arguments for your CLI version.
Many accounts never need this step. Workspaces created recently are often enabled for Unity Catalog automatically. In that case Databricks assigns the workspace to the regional metastore, and creates one if none exists yet. Check your account's behavior before assuming either way.
What changes after assignment
Once the assignment is in place, users in the workspace get these things:
- The three-level namespace works:
catalog.schema.table. SHOW CATALOGSlists the catalogs the user is allowed to see.- Privileges from
GRANTstatements are enforced for queries run on Unity Catalog compatible compute. - Audit and lineage information for queries goes to the account-level system.
Nothing is moved or deleted. The legacy per-workspace Hive metastore stays available as the hive_metastore catalog. Existing tables in it are untouched, but they are not governed by Unity Catalog until you migrate them.
Compute must be compatible
Assignment alone does not guarantee that a given cluster enforces Unity Catalog. The cluster needs an access mode that supports it. Standard (formerly shared) and dedicated (formerly single user) access modes do. Older "no isolation shared" clusters cannot access Unity Catalog data. If a user sees errors about missing catalogs or unsupported compute, check the cluster's access mode and runtime version first.
SQL warehouses and serverless compute support Unity Catalog by default.
Verifying the assignment
Run these statements in a notebook or the SQL editor of the workspace:
SELECT current_metastore();
SELECT current_catalog(), current_schema();
SHOW CATALOGS;current_metastore() returns the metastore identifier. It has the form cloud:region:metastore-uuid. If two workspaces return the same value, they share a metastore. If the call fails, or SHOW CATALOGS lists only hive_metastore, the workspace is probably not assigned, or the compute is not compatible.
current_catalog() shows the default catalog that unqualified names resolve against. Admins can set a default catalog for a workspace so that users who write SELECT * FROM orders land in a sensible place. Use USE CATALOG to change the catalog for one session:
USE CATALOG dev;
USE SCHEMA sales;
SELECT * FROM orders;Prefer fully qualified names in shared jobs. A job that relies on a default catalog can behave differently in two workspaces with different defaults.
One metastore, many workspaces: isolation
Sharing a metastore does not mean every workspace must see every catalog. By default, a catalog is accessible from all workspaces assigned to the metastore, subject to privileges. Databricks lets you bind a catalog to specific workspaces. A catalog bound to only the production workspace is invisible from the development workspace, even for users who hold privileges on it.
Privileges and bindings work together:
| Layer | Question it answers |
|---|---|
| Metastore assignment | Can this workspace use this metastore at all? |
| Workspace binding | Can this workspace see this catalog? |
| Privileges | Can this user or group do this on this object? |
A user needs all three to succeed. This is useful for separating environments, as the design chapter explains later.
Changing or removing an assignment
You can unassign a workspace in the account console. Be careful, because the effects are immediate for users:
- Queries that use three-level names fail in that workspace.
- Jobs that read or write Unity Catalog tables fail on their next run.
- The data is not deleted. Tables, grants, and storage remain in the metastore and in cloud storage.
- Reassigning the same metastore restores access.
Assigning a workspace to a different metastore changes what the same names point to. A job that reads dev.sales.orders may now find a different table, or none. Treat reassignment as a migration, not a setting change.
Deleting a metastore is much more serious than unassigning it. Do not delete a metastore to fix an assignment problem.
Common errors
- Region mismatch. The workspace does not appear in the assignment list because it is in a different region from the metastore. Create a metastore in that region.
- Missing role. The Assign option is unavailable because you are not an account admin.
- Incompatible cluster. The workspace is assigned, but the cluster's access mode cannot use Unity Catalog.
- Wrong default catalog. Unqualified names resolve to
hive_metastoreor an unexpected catalog. Use qualified names or setUSE CATALOG. - Assuming cross-workspace visibility. A catalog is bound to other workspaces, so a team cannot see it from theirs.
Exercise
Your account has workspaces in two regions, and you want a single metastore to serve all of them. Why does this not work, and what are two ways to share data between the regions?
Show answer
A metastore and its workspaces must be in the same region, so each region needs its own metastore. To share data across regions you can use Delta Sharing between the two metastores, or copy the data into storage that the second metastore manages.
Exercise
A user in a workspace that is assigned to a metastore runs SHOW CATALOGS on an older cluster and sees only hive_metastore. Name two things you would check.
Show answer
First check the cluster's access mode and runtime version, since clusters without Unity Catalog support cannot see its catalogs. Then check that the workspace is actually assigned, for example by running SELECT current_metastore(); on compatible compute or by looking at the metastore's Workspaces tab. You could also check whether the catalogs are bound to other workspaces only.