Sub topic 5
Catalogs
This chapter covers the catalog, the first level of the three-level namespace. It assumes you know basic SQL, have used a Databricks workspace or the SQL editor, and have read the earlier chapters on the metastore and the namespace.
What a catalog is
A catalog is the top-level container for data inside a metastore. Each catalog holds schemas, and schemas hold tables, views, volumes, and functions. In a fully qualified name such as dev.sales.orders, dev is the catalog.
Catalogs matter for three reasons:
- They are the broadest unit of organization. Most teams use catalogs to separate environments, business units, or data domains.
- They are a privilege boundary. A grant on a catalog is inherited by everything beneath it.
- They can carry their own storage location for managed tables, and they can be limited to certain workspaces.
Catalog types
Not every catalog is a normal one you create with SQL. You will see several kinds in the catalog list:
| Kind | Purpose |
|---|---|
| Standard catalog | Holds data governed by Unity Catalog. This is the kind you create yourself. |
| `system` catalog | Read-only catalog provided by Databricks, with metadata such as audit and lineage information. |
| Foreign catalog | Mirrors a database in an external system through Lakehouse Federation. |
| Shared catalog | Created from a Delta Sharing share, so you can read data another organization provides. |
| `hive_metastore` | Shows the legacy workspace-local Hive metastore. It appears in the list but is not governed by Unity Catalog. |
This chapter focuses on standard catalogs.
Creating a catalog
Creating a catalog needs the CREATE CATALOG privilege on the metastore. Metastore admins have it, and they can grant it to others. The creator becomes the catalog's owner.
CREATE CATALOG IF NOT EXISTS dev
COMMENT 'Development environment for all teams';IF NOT EXISTS makes the statement safe to re-run. COMMENT is optional, but it helps people who browse the catalog later.
Catalog names are limited. They cannot contain spaces, periods, or forward slashes. Unity Catalog stores names in lowercase. If a name contains a hyphen, you must wrap it in backticks every time you use it, for example ` dev-eu `. Using underscores avoids the problem.
Choosing where managed data goes
Managed tables in a catalog need a storage location. Unity Catalog looks for one in this order:
- The schema's managed location, if one is set.
- The catalog's managed location, if one is set.
- The metastore's storage root, if the metastore has one.
If none of these exists, creating a managed table fails. Setting the location at catalog level is a common way to give each environment or business unit its own storage:
CREATE CATALOG IF NOT EXISTS finance
MANAGED LOCATION 's3://example-bucket/finance'
COMMENT 'Finance data with its own storage path';The bucket name is a placeholder. The path must be covered by an external location, and you need the CREATE MANAGED STORAGE privilege on that external location. Storage credentials and external locations are covered in a later chapter.
Listing and selecting catalogs
SHOW CATALOGS lists the catalogs you can see. You see only catalogs where you hold some privilege or own the object.
SHOW CATALOGS;
DESCRIBE CATALOG EXTENDED dev;DESCRIBE CATALOG EXTENDED shows the owner, the comment, and the storage root used for managed tables.
You can refer to a catalog in every statement by its full name. You can also set a session default so that shorter names resolve against it:
USE CATALOG dev;
USE SCHEMA sales;
SELECT * FROM orders;USE CATALOG changes only the current session. When the session ends, the setting is gone. Each workspace also has a default catalog, which applies when a session has not run USE CATALOG. Workspace admins can change it. Code that relies on the default catalog can therefore behave differently from one workspace to another. Fully qualified names, or an explicit USE CATALOG at the top of a notebook, avoid that problem.
You can also check the current setting:
SELECT current_catalog(), current_schema();Access to a catalog
A user can touch an object only if they have the right privileges on the object and on its parents. For a catalog, the key privileges are these:
| Privilege | What it allows |
|---|---|
| `USE CATALOG` | Resolve the catalog's name. Needed before any child object can be reached. |
| `USE SCHEMA` | Needed on a schema, in addition to `USE CATALOG`, to reach objects in it. |
| `CREATE SCHEMA` | Create schemas inside the catalog. |
| `SELECT`, `MODIFY` | Read or write tables. When granted on a catalog, they are inherited by all tables beneath it. |
| `ALL PRIVILEGES` | Every privilege that can be granted at this level. |
The following statements give a group the ability to reach a catalog, and then to read from it:
GRANT USE CATALOG ON CATALOG dev TO `data-analysts`;
GRANT USE SCHEMA ON SCHEMA dev.sales TO `data-analysts`;
GRANT SELECT ON TABLE dev.sales.orders TO `data-analysts`;All three grants are needed for the group to query that one table. SELECT alone is not enough, because the group cannot reach the table without USE CATALOG and USE SCHEMA on the parents.
Privileges granted on a catalog flow down to every schema and table inside it, including ones created later. A grant at catalog level is therefore powerful, and it is easy to make too broad. Granting SELECT on prod gives read access to every table in every schema of prod.
Ownership
The owner of a catalog can grant privileges on it, rename it, and drop it. The owner also keeps those rights without any explicit grant. To avoid depending on one person, transfer ownership to a group:
ALTER CATALOG dev OWNER TO `platform-admins`;When an owner leaves the organization, a catalog owned by that individual becomes hard to administer. An owner that is a group avoids this.
Changing and dropping catalogs
You can change the comment, the owner, and some properties with ALTER CATALOG. Renaming is possible too, but queries and jobs that use the old name will break:
ALTER CATALOG dev RENAME TO development;Dropping a catalog needs ownership or the right privilege. A catalog that still contains schemas cannot be dropped unless you add CASCADE, which also drops everything inside it:
DROP CATALOG IF EXISTS scratch CASCADE;Limiting a catalog to some workspaces
By default, a catalog is visible from every workspace attached to the metastore, subject to privileges. A catalog can instead be bound to specific workspaces. This is called an isolated catalog. Users in other workspaces cannot reach it, even if they hold privileges on it.
Binding is useful for separating production from development. Access is then limited by two things: who the user is, and which workspace they are working in. Workspace binding is configured in the catalog's settings in Catalog Explorer or through the API. It is not done with SQL GRANT.
Common mistakes
- Missing
USE CATALOG. A user hasSELECTon a table but still gets a permission error. Check thatUSE CATALOGandUSE SCHEMAwere granted on the parents. - Relying on the default catalog. A notebook that uses a short name works in one workspace and fails or reads different data in another. Set the catalog explicitly.
- Hyphens in names.
CREATE CATALOG dev-eufails to parse. Usedev_eu, or add backticks everywhere. - No storage location. Creating a managed table fails because neither the schema, the catalog, nor the metastore has a managed location.
- Over-broad catalog grants. Granting at catalog level when schema level would do gives access to far more data than intended.
Exercise
A group has SELECT on dev.sales.orders, but its members get a permission error when they query the table. Which privileges are most likely missing, and on which objects?
Show answer
USE CATALOG on the catalog dev and USE SCHEMA on the schema dev.sales. A table can be reached only if the user can also reach its parent catalog and schema.
Exercise
You want a finance catalog whose managed tables are stored under their own cloud path, instead of in the metastore's default storage. Which clause of CREATE CATALOG do you use, and what must already exist for it to work?
Show answer
Use MANAGED LOCATION '<path>'. The path must be covered by an external location, and you need the CREATE MANAGED STORAGE privilege on that external location.