how to create catalog

PraveenReddy21
New Contributor III

Hi ,

I am trying to create  catalog  and database  its not  allowing  databricks  , please  suggest  .

Here my code .

base_dir = "/mnt/files"
spark.sql(f"CREATE CATALOG IF NOT EXISTS dev")
spark.sql(f"CREATE DATABASE IF NOT EXISTS dev.demo_db")
 
first i need to create  catalog then after  under catalog  i want to create database.
 
Thank You .
Praveen.

 

szymon_dybczak
Esteemed Contributor III

Hi @PraveenReddy21 ,

What error do you get? Do you use Unity Catalog or Hive metastore?

Hi ,

Please  find the below  error

AnalysisException: [RequestId=2e102048-fdde-4293-8cfe-8f0d866e5a1c ErrorClass=INVALID_STATE] Metastore storage root URL does not exist. Please provide a storage location for the catalog (for example 'CREATE CATALOG myCatalog MANAGED LOCATION '<location-path>'). Alternatively set up a metastore root storage location to provide a storage location for all catalogs in the metastore.

JairoCollante
New Contributor II

I got a similar error trying create a catalog with "databricks.sdk" library I resolved it add the parameter "storage_root":

 
w.catalogs.create(name=c.name, storage_root='s3://databricks-workspace-bucket/unity-catalog/426335709')
 
In my case all catalog are MANAGED, so I took this value of previous catalog created.