Sub topic 2
The metastore: the top-level container
This chapter assumes you know basic SQL (CREATE, SELECT, INSERT), have used a Databricks workspace with notebooks or the SQL editor, and understand that tables are stored as files in cloud object storage. It also assumes you have a general idea of users, groups, and access control.
What a metastore is
A 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 types, storage locations, and permissions. The metastore does not hold the data files themselves. Those stay in cloud object storage.
Everything you create in Unity Catalog lives somewhere below a metastore. Catalogs sit directly under it, schemas sit under catalogs, and tables sit under schemas. No object exists outside a metastore.
What a metastore contains
A metastore tracks several kinds of things.
- Catalogs, schemas, tables, views, volumes, and functions.
- Privileges, which record who may do what to each object.
- Storage credentials and external locations, which control access to cloud storage paths.
- Other shared objects, such as connections to external systems.
Because all of this sits in one place, permissions and object definitions are managed once. They are not copied into each workspace.
One metastore per region
A metastore belongs to a single cloud region. A common setup is one metastore for each region where you run Databricks. A workspace in that region can use the metastore. A workspace in a different region cannot use it directly.
This has a practical effect. Data and permissions defined in one metastore are not automatically visible in another. If your company works in two regions, plan for two metastores and decide how data moves between them.
Why a shared metastore matters
Without Unity Catalog, each workspace kept its own table definitions and its own access rules. Two workspaces could describe the same data in different ways, and you had to keep permissions in step by hand.
With a shared metastore, several workspaces see the same catalogs, and one GRANT applies everywhere the metastore is attached. A group that can read dev.sales.orders in one workspace can read it in any other workspace using the same metastore, as long as that workspace has access to the data.
Seeing which metastore you use
You can check the metastore your session is using with built-in functions.
SELECT current_metastore();
SELECT current_catalog(), current_schema();The first query returns the identifier of the metastore attached to your workspace. The second shows the catalog and schema your session uses when you write a short table name. Both are useful when you suspect you are connected to the wrong environment.
Who manages the metastore
A metastore has an admin role. A metastore admin can create catalogs, manage grants across the metastore, and control storage credentials and external locations. Treat this role as powerful and give it to a small group, not to many individual users. Day-to-day work should happen with ordinary privileges on specific catalogs and schemas.
Common errors
- Expecting data to be inside the metastore. The metastore stores metadata. Deleting a metastore entry for an external table does not mean the files in cloud storage are your only copy of the definition, but the files themselves are separate objects.
- Assuming a workspace sees every metastore. A workspace is attached to one metastore at a time, and it must be in the same region.
- Giving the metastore admin role too widely. This bypasses the careful grants you design later in the tutorial.
- Querying with the wrong default catalog. If a short table name fails, check
current_catalog()first.
Exercise
A company runs Databricks workspaces in two cloud regions. How many metastores does it need at minimum, and why?
Show answer
Two, one for each region. A metastore is tied to a single region, and only workspaces in that region can be attached to it. Workspaces in the same region can share one metastore, so they see the same catalogs and permissions.