cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Start and stop lakebase instance

juanjomendez96
New Contributor III

Hello there!

I have been using the databricks-sdk for a while, and I have managed to create a system where I have controlled when the clusters and applications start and stop.

However, now that we have adopted the new lakebase feature, we were wondering if we can do the same for those instances.

In the documentation (https://databricks-sdk-py.readthedocs.io/en/latest/dbdataclasses/database.html#databricks.sdk.servic...), I cannot see anything similar to what exists for applications and clusters.

For more context, we have scheduled a job that stops one of our applications doing the following:

if action == "stop" and cluster_status == "RUNNING":
        print(f"Stopping cluster_id {cluster_id}")
        w.clusters.delete(cluster_id)
    
    elif action == "start" and cluster_status == "STOPPED":
        print(f"Starting cluster_id {cluster_id}")
        w.clusters.start(cluster_id)

By having the cluster_id, we can start or stop the cluster automatically.

Does anyone from this community know how can we achieve something similar but for lakebase instances?

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions

szymon_dybczak
Esteemed Contributor III

 

Sure, @juanjomendez96 . You just need to use following code from python SDK:

from databricks.sdk import WorkspaceClient
from databricks.sdk.service.database import DatabaseInstance

# Initialize the Workspace client
w = WorkspaceClient()

# Stop a database instance
instance_name = "my-database-instance"
w.database.update_database_instance(
name=instance_name,
database_instance=DatabaseInstance(
name=instance_name,
stopped=True
),
update_mask="*"
)
print(f"Stopped database instance: {instance_name}")

# Start a database instance
w.database.update_database_instance(
name=instance_name,
database_instance=DatabaseInstance(
name=instance_name,
stopped=False
),
update_mask="*"
)
print(f"Started database instance: {instance_name

View solution in original post

5 REPLIES 5

Isi
Honored Contributor II

Hello @juanjomendez96 

I believe this documentation covers exactly what youโ€™re looking for. Just keep in mind that this feature is still in Public Preview, and as highlighted at the top of the page, it may not yet be available in your region.

"This feature is in Public Preview in the following regions: us-east-1, us-west-2, eu-west-1, ap-southeast-1, ap-southeast-2, eu-central-1, us-east-2, ap-south-1."


Hope this helps ๐Ÿ™‚

Isi

juanjomendez96
New Contributor III

Hello @Isi thanks for your fast response in the matter. Actually I have lakebase enabled in my region, the only problem was that I did not fully understand the documentation. 

Thanks anyways ๐Ÿ˜‰ 

szymon_dybczak
Esteemed Contributor III

 

Sure, @juanjomendez96 . You just need to use following code from python SDK:

from databricks.sdk import WorkspaceClient
from databricks.sdk.service.database import DatabaseInstance

# Initialize the Workspace client
w = WorkspaceClient()

# Stop a database instance
instance_name = "my-database-instance"
w.database.update_database_instance(
name=instance_name,
database_instance=DatabaseInstance(
name=instance_name,
stopped=True
),
update_mask="*"
)
print(f"Stopped database instance: {instance_name}")

# Start a database instance
w.database.update_database_instance(
name=instance_name,
database_instance=DatabaseInstance(
name=instance_name,
stopped=False
),
update_mask="*"
)
print(f"Started database instance: {instance_name

Hello @szymon_dybczak this worked like a charm. Thanks a lot!

No problem @juanjomendez96  ๐Ÿ™‚

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local communityโ€”sign up today to get started!

Sign Up Now