Watch this on You Tube https://www.youtube.com/watch?v=Yo0x4u6jc4M
๐ If youโd like to learn Azure Databricks step by step, check out the full playlist here:
๐ https://www.youtube.com/playlist?list=PLNj2XeCNjFeosTuxZLjfYvnW4H1hsPH07
๐ Introduction
In todayโs data-driven world, organizations need a scalable, open, and flexible way to manage data across storage and compute platforms. Azure Databricks and Apache Iceberg together offer exactly that!
In this blog, weโll explore how to connect Azure Databricks to Azure PostgreSQL and create an Apache Iceberg table using a simple, step-by-step approach. This approach helps you modernize your data lake and unlock new possibilities for analytics and machine learning. ๐
๐ก What is Apache Iceberg?
Apache Iceberg is an open table format designed for large-scale, analytic datasets stored in data lakes. It brings data warehouse-like reliability to the data lake by supporting:
- โ ACID transactions
- โ Schema evolution
- โ Partition evolution
- โ Time travel queries
- โ Hidden partitioning
With Iceberg, you can build a true lakehouse architecture that combines the performance of a warehouse with the flexibility of a data lake.
๐งฉ Why Connect Azure Databricks with Azure PostgreSQL?
Azure PostgreSQL often stores transactional or operational data. But for large-scale analytics, itโs better to replicate or move that data to Iceberg tables in Azure Databricks. This gives you:
- โก Faster query performance
- ๐ง Seamless integration with Spark and ML workloads
- ๐งฑ Data versioning and audit support
- โ๏ธ Scalable, cost-efficient storage
โ๏ธ Prerequisites
Before we begin, ensure you have:
- โ Access to an Azure Databricks Workspace
- โ A running Azure PostgreSQL Flexible Server
- โ Correct JDBC connection details (hostname, port, username, password)
- โ A Databricks cluster with Iceberg support enabled
๐ช Step-by-Step: Creating an Iceberg Table from Azure PostgreSQL
Letโs go hands-on and build it! ๐
๐น Step 1: Define Connection Details
In your Databricks notebook, start by specifying the PostgreSQL connection details.
jdbcHostname = "jbpos-sql-vnet.postgres.database.azure.com"
jdbcPort = 5432
jdbcDatabase = "postgres"
jdbcUrl = f"jdbc:postgresql://{jdbcHostname}:{jdbcPort}/{jdbcDatabase}"
connectionProperties = {
"user": "jvivek2k1",
"password": "xxxxxxxxx",
"driver": "org.postgresql.Driver"
}
Here:
jdbcHostnameโ your PostgreSQL server namejdbcDatabaseโ the database you want to connect touserandpasswordโ your login credentialsdriverโ PostgreSQL JDBC driver class
๐น Step 2: Read Data from Azure PostgreSQL
Now, letโs pull data from your public.customer table in PostgreSQL into a Spark DataFrame.
df = spark.read.jdbc(
url=jdbcUrl,
table='public.customer',
properties=connectionProperties
)
โ
This reads all rows and columns from your PostgreSQL table into Spark.
You can verify the data with:
display(df)
๐น Step 3: Write Data to an Iceberg Table
Once the data is in Databricks, we can save it as an Iceberg Table in the Unity Catalog or Hive Metastore.
df.write.format("iceberg") \
.mode("overwrite") \
.saveAsTable("finance.default.postgres_customer_iceberg")
๐น Step 4: Validate the Iceberg Table
After writing, you can run SQL queries in Databricks SQL or the notebook itself to validate the table:
SELECT * FROM finance.default.postgres_customer_iceberg;
๐ Benefits of Using Iceberg Tables in Azure Databricks
1๏ธโฃ High Performance Queries โ Iceberg handles large datasets efficiently with advanced partition pruning and metadata optimization.
2๏ธโฃ Schema Evolution โ Add or modify columns without rewriting entire datasets.
3๏ธโฃ Data Time Travel โ Query data as it existed at any previous point in time.
4๏ธโฃ Open Source & Interoperable โ Works with multiple engines (Spark, Trino, Flink, Snowflake, etc.).
5๏ธโฃ Cost-Effective Storage โ Store data in open formats on low-cost cloud storage.
๐๏ธ Real-World Use Cases
- Building a Data Lakehouse from operational systems
- Creating auditable, version-controlled datasets
- Simplifying ETL pipelines by standardizing on Iceberg tables
- Enabling ML workloads with consistent and reliable data layers
๐ง Pro Tips
๐ฌ Use Azure Key Vault integration to securely store your PostgreSQL credentials instead of embedding them in code.
โ๏ธ Use Incremental Loads instead of full overwrite for production pipelines.
๐ Consider using partition columns for large tables to improve query performance.
๐ฏ Summary
In this blog, we:
โ
Connected Azure Databricks to Azure PostgreSQL
โ
Loaded data from a PostgreSQL table into Databricks
โ
Created an Apache Iceberg table for modern data analytics
โ
Validated the data through SQL queries
By combining Azure Databricks + Apache Iceberg + Azure PostgreSQL, youโre enabling a modern, open, and scalable data lakehouse architecture thatโs built for performance and flexibility. ๐ช
Thank You,
Vivek Janakiraman
Disclaimer:
The views expressed on this blog are mine alone and do not reflect the views of my company or anyone else. All postings on this blog are provided โAS ISโ with no warranties, and confers no rights.
- Apache Iceberg
- Apache Iceberg Tutorial
- Azure Data Engineering Tutorial
- azure databricks
- Azure Databricks Demo
- Azure Databricks for beginners
- Azure Databricks Real Time Example
- Azure Databricks SQL
- Azure Databricks step by step
- azure databricks tutorial
- Azure PostgreSQL
- Azure PostgreSQL Flexible Server
- Data Lakehouse Architecture
- Databricks Data Engineering
- Databricks Data Lake
- Databricks Iceberg Table
- Databricks JDBC Connection
- Databricks Notebook Tutorial
- Databricks PostgreSQL Integration
- Databricks tutorial 2025
- Iceberg Table Creation
- Iceberg Table in Databricks
- Iceberg vs Delta
- PostgreSQL to Databricks Connection
- PostgreSQL to Iceberg