Sub topic 2
The metastore: the top-level container
Prerequisites
This chapter assumes you can write basic SQL (CREATE, SELECT, INSERT) and have used a Databricks workspace with notebooks or the SQL editor. It also assumes you know that tables are stored as files in cloud object storage, and that you understand users, groups, and access control in general.
What the metastore is
The metastore is the top-level container in Unity Catalog. It holds the metadata that describes your data and the rules for who can use it. Metadata means information about data: table names, column names and types, where the files live, and which groups have which privileges. The metastore does not hold your table rows. Those stay in cloud object storage.
Everything you create in Unity Catalog sits below a metastore. The order, from top to bottom, is:
- Metastore
- Catalog
- Schema
- Table, view, volume, or function
Later chapters cover each level. This chapter covers the top one, because every name, grant, and storage setting depends on it.
What a metastore contains
A metastore holds these kinds of objects. Each kind of object that you can grant privileges on is called a securable object.
- Catalogs. The first level of the three-level namespace. Each catalog holds schemas.
- Storage credentials and external locations. These define how Unity Catalog reaches your cloud storage. The chapter on storage access covers them in detail.
- Metadata about every object below. This includes schemas, tables, views, volumes, and functions.
- Access control rules. Grants are stored in the metastore, so they apply the same way wherever the data is accessed.
- Other metastore-level objects. Depending on your setup, these can include things such as shares for data sharing and connections to external systems.
Because the metastore stores grants centrally, you define a rule once. A group that has SELECT on a table has it in every workspace attached to that metastore.
Why one metastore matters
Before Unity Catalog, each Databricks workspace typically had its own Hive metastore. Users, groups, and permissions were managed per workspace. The same table could be governed differently in two workspaces, and you had to repeat the setup in each one.
A Unity Catalog metastore removes that duplication. You manage identities, privileges, and data definitions in one place. Several workspaces then share them.
Region boundaries
A metastore belongs to one cloud region. You can attach it only to workspaces in that same region. This has practical consequences:
- If your company runs workspaces in two regions, you need at least two metastores, one per region.
- Catalogs in different metastores are separate. You cannot query across them with a normal three-level name.
- To share data between metastores, use a data sharing feature such as Delta Sharing instead of trying to merge them.
Most organizations use one metastore per region and keep it that way. Creating extra metastores in the same region is not supported, and it would defeat the point of central governance.
Attaching a metastore to workspaces
A metastore does nothing for a workspace until it is attached, which Databricks calls assignment. After you assign a metastore to a workspace, users in that workspace can see the catalogs they have privileges on. The workspace is now governed by Unity Catalog.
Key points about assignment:
- A workspace can be attached to one metastore at a time.
- One metastore can be attached to many workspaces, as long as they are in the same region.
- Assignment is done by an account administrator or a metastore administrator. It is done in the account console, with the API, or with infrastructure tools such as Terraform. You do not do it with SQL.
- Newer accounts may get a metastore assigned automatically when a workspace is created. Check what your account did before you create a new one.
Checking which metastore you are using
From a notebook or the SQL editor in an attached workspace, you can ask for the current metastore and your current context:
SELECT current_metastore();
SELECT current_catalog(), current_schema();current_metastore() returns the identifier of the metastore that serves your workspace. If a workspace is not attached to a metastore, Unity Catalog commands will fail or the three-level names will not resolve. This check is a quick first step when someone reports that a catalog "does not exist".
You can also list what the metastore exposes to you. You only see objects you have some privilege on, so two people can get different lists:
SHOW CATALOGS;Metastore storage and the metastore admin
A metastore can have an optional root storage location. It is a cloud storage path that serves as a default home for managed data when no catalog or schema sets a more specific location. Many current setups skip it and give each catalog its own managed storage instead. The chapter on storage access explains the order in which Unity Catalog picks a location.
A metastore also has an owner, often called the metastore admin. Common choices are a group rather than one person, so that control does not depend on one account. The admin can create catalogs and manage grants at the top. Ownership is covered in the chapter on principals and ownership.
Common errors
These are the problems you are most likely to meet at this level.
| Symptom | Likely cause | What to check |
|---|---|---|
| `Catalog 'dev' does not exist` | The workspace is not attached to the expected metastore, or you lack privileges. | Run `SELECT current_metastore();`, then ask the owner of the catalog to check your grants. |
| A colleague sees a catalog you do not | Grants differ between you. `SHOW CATALOGS` lists only objects you may use. | Compare group membership and grants. |
| Cannot attach a metastore to a workspace | The metastore and workspace are in different regions. | Compare regions in the account console. |
| Same table name works in one workspace but not another | The workspaces use different metastores. | Run `SELECT current_metastore();` in each. |
| Old tables are missing after Unity Catalog is enabled | They are in the legacy Hive metastore, which is separate from Unity Catalog. | Look in the `hive_metastore` catalog, or migrate the tables. |
Legacy Hive metastore and Unity Catalog
In workspaces with Unity Catalog, the old workspace-local Hive metastore usually still shows up as a catalog named hive_metastore. It is not part of the Unity Catalog governance model. Tables in it do not get Unity Catalog grants, and it is not shared between workspaces. Treat it as a legacy area. Plan to migrate tables from it into Unity Catalog catalogs, where governance applies.
Design guidance
When you plan a metastore, keep these rules in mind.
- Use one metastore per region where you have workspaces.
- Put every workspace in that region on the metastore, so that governance is consistent.
- Do not create separate metastores to separate environments such as dev and prod. Use catalogs for that, and use grants to limit access. Later chapters show this pattern.
- Own the metastore with a group.
- Keep metastore-level privileges, such as creating catalogs, with a small set of trusted people.
Summary
The metastore is the root container for Unity Catalog metadata and access rules. It lives in one region, serves many workspaces once attached, and contains catalogs and the objects below them. It stores definitions and grants, not your table data. With that in place, the next chapters move down the hierarchy to the three-level namespace.
Exercise
Your company has workspaces named dev and prod in the same cloud region, and a third workspace named analytics in a different region. How many Unity Catalog metastores do you need at minimum, and which workspaces can share a metastore? Why would you not create a separate metastore for dev and another for prod to keep them apart?
Show answer
You need at least two metastores, because a metastore belongs to one region. The dev and prod workspaces can share the metastore in their region, and analytics needs the metastore for its own region. You should not split dev and prod into separate metastores, because that duplicates governance and blocks simple cross-environment queries. Use separate catalogs, such as dev and prod, and control access with grants instead.
Exercise
A user reports that SELECT * FROM dev.sales.orders fails with "catalog does not exist" in one workspace but works in another. Name two SQL checks you would run, and one likely cause.
Show answer
Run SELECT current_metastore(); in both workspaces to see whether they use the same metastore, and run SHOW CATALOGS; as the affected user to see which catalogs are visible. A likely cause is that the failing workspace is attached to a different metastore, or the user has no privilege on the dev catalog, so it is hidden from them.