|
| 1 | +# OLTP database instance with a catalog |
| 2 | + |
| 3 | +This example demonstrates how to define an OLTP database instance and a database catalog in a Databricks Asset Bundle. |
| 4 | + |
| 5 | +It includes and deploys an example database instance and a catalog. When data changes in the database instance, they are reflected in Unity Catalog. |
| 6 | + |
| 7 | +For more information about Databricks database instances, see the [documentation](https://docs.databricks.com/aws/en/oltp/). |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +* Databricks CLI v0.265.0 or above |
| 12 | +* `psql` client version 14 or above (only needed to run the demo data generation) |
| 13 | + |
| 14 | +## Usage |
| 15 | + |
| 16 | +Modify `databricks.yml`: |
| 17 | +* Update the `host` field under `workspace` to the Databricks workspace to deploy to |
| 18 | + |
| 19 | +Run `databricks bundle deploy` to deploy the bundle. |
| 20 | + |
| 21 | +Please note that after this bundle gets deployed, the database instance starts running, which incurs cost. |
| 22 | + |
| 23 | +Run the following queries to populate your database with sample data: |
| 24 | + |
| 25 | +```bash |
| 26 | +# Create a demo table: |
| 27 | +databricks psql my-instance -- -d my_database -c "CREATE TABLE IF NOT EXISTS hello_world (id SERIAL PRIMARY KEY, message TEXT, number INTEGER, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);" |
| 28 | + |
| 29 | +# Insert 100 rows of demo data: |
| 30 | +databricks psql my-instance -- -d my_database -c "INSERT INTO hello_world (message, number) SELECT 'Hello World #' || generate_series, generate_series FROM generate_series(1, 100);" |
| 31 | + |
| 32 | +# Show generated rows: |
| 33 | +databricks psql my-instance -- -d my_database -c "SELECT * FROM hello_world;" |
| 34 | +``` |
| 35 | + |
| 36 | +Open your catalog in Databricks: `databricks bundle open my_catalog` |
| 37 | +Navigate to the `public` schema, then to the `hello_world` table, then to "Sample data" and explore your generated data. |
| 38 | + |
| 39 | +## Clean up |
| 40 | +To remove the provisioned instance and catalog run `databricks bundle destroy` |
0 commit comments