Sub topic 3
Attaching a metastore to workspaces
This chapter assumes you know basic SQL, can work in a Databricks workspace (notebook or SQL editor), and understand that tables are files in cloud object storage. It builds on the previous chapter, where the metastore is the top-level container for Unity Catalog metadata.
Why attachment matters
A metastore does nothing until a workspace uses it. A workspace is a Databricks environment where users run notebooks, queries, and jobs. The link between the two is called an assignment. When a workspace is assigned to a metastore, every catalog, schema, and table in that metastore becomes visible in the workspace, subject to privileges.
Three rules shape how this works:
- A workspace can be assigned to only 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.
The second rule is the useful one. If development, staging, and production workspaces share a metastore, they see the same governed data and the same grants. You manage access once, not once per workspace.
Who does the attaching
Assignment is an administrative task. It is done by an account admin, using the account console or the Databricks API, not by a regular workspace user. The usual steps are:
- Create the metastore in the account, in the region where your workspaces run.
- Choose the workspaces that should use it.
- Assign the metastore to each workspace.
Many accounts never do this by hand. Newer workspaces are often attached to a regional metastore automatically when they are created. Check before you create a new one, because a second metastore in the same region splits your data governance into two separate islands.
Checking what a workspace is using
From a workspace, you can confirm that Unity Catalog is active by listing catalogs and checking the current metastore.
SELECT current_metastore();
SHOW CATALOGS;current_metastore() returns the ID of the metastore the workspace is attached to. If SHOW CATALOGS returns catalogs such as system or ones you created, the workspace is using Unity Catalog. Two workspaces that return the same ID share one metastore.
What changes after attachment
Once attached, you can address tables with the three-level name catalog.schema.table, and privileges you grant apply in every attached workspace. Access also depends on the compute you use. A cluster or SQL warehouse must run in a mode that supports Unity Catalog, or it cannot read these objects even though the workspace is attached.
Common errors
- No catalogs appear, or three-level names fail. The workspace may not be assigned to a metastore, or the compute is not Unity Catalog capable. Check
current_metastore()first, then the cluster's access mode. - A metastore cannot be selected for a workspace. The regions differ. Create a metastore in the workspace's region instead.
- Data seems to differ between workspaces. They are probably attached to different metastores. Compare the IDs returned by
current_metastore(). - Assuming a grant is global. A grant lives in one metastore. It does not follow your users to a workspace attached to another metastore.
Exercise
Your company has a dev workspace and a prod workspace in the same region. You want one set of grants to govern both. What would you do, and how can you check that it worked?
Show answer
Have an account admin assign both workspaces to the same metastore. Then run SELECT current_metastore() in each workspace. If both return the same ID, they share the metastore and its grants.