The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
In today's digital landscape, securing connections between services is more important than ever. This article will guide you through the process of connecting Microsoft Fabric Notebook to an Azure Database for PostgreSQL using Managed Private Endpoints (MPE). By following these steps, you can ensure that all outbound traffic remains on the private network, enhancing security. Whether you're an admin with Fabric workspace access or have sufficient rights in Azure, this comprehensive guide will provide you with the necessary prerequisites and step-by-step instructions to achieve a secure connection. Dive in to learn how to set up, approve, and validate your private endpoint, ensuring your Fabric environment can securely communicate with the Azure PostgreSQL database without exposing it to the public internet.
Connect a Microsoft Fabric Notebook to an Azure Database for PostgreSQL securely using a Managed Private Endpoint (MPE). This ensures outbound traffic stays on the private network.
Before you begin, ensure you have the following:
Register the Microsoft.Network provider (if not done): In the Azure Portal, go to your Subscription settings. Under Resource Providers, find Microsoft.Network and click Register. (This only needs to be done once per subscription; it will take a few minutes).
Copy Resource ID: Open your Azure PostgreSQL server’s Properties page in the portal and copy the full Resource ID. The Resource ID looks like:
/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{server-name}
.
Create a Managed Private Endpoint in Fabric:
Approve the Private Endpoint in Azure:
Confirm the Endpoint is Active in Fabric: Return to the Fabric workspace settings and refresh the Managed Private Endpoints section. The status for your endpoint should update to Approved/Succeeded once the Azure side is approved. This means the private link is established. The Fabric environment can now privately access the PostgreSQL server.
Connect to the PostgreSQL Database from Fabric Notebook:
With the managed private endpoint in place, you can connect to the database from Fabric experiences (e.g. Spark notebooks or Dataflows) securely:
<server-name>.postgres.database.azure.comand its database name, along with the required credentials (username/password). Use the standard PostgreSQL JDBC connection string or connector settings, but no special VPN is needed – the traffic will route through the private endpoint.
jdbc:postgresql://<server-name>.postgres.database.azure.com:5432/<database>and provide your user credentials. Fabric will utilize the managed private endpoint to reach the server securely.
serverName = "<server_name>.database.windows.net" database = "<database_name>" dbPort = 5432 dbUserName = "<username>" dbPassword = "<db password> or reference based on Keyvault>” from pyspark.sql import SparkSession spark = SparkSession.builder \ .appName("ExamplePostgres") \ .config("spark.jars.packages", "org.postgresql:postgresql:42.2.18") \ .getOrCreate() # Construct JDBC URL for PostgreSQL jdbcURL = f"jdbc:postgresql://{serverName}:{dbPort}/{database}" # Connection properties connection = { "user": dbUserName, "password": dbPassword, "driver": "org.postgresql.Driver" } # Read data from PostgreSQL table df = spark.read.jdbc(url=jdbcURL, table="person.Contact", properties=connection) df.show() display(df) # Write the dataframe as a delta table in your lakehouse df.write.mode("overwrite").format("delta").saveAsTable("Contact")
Finally, run a small query or operation from Fabric to the database (for instance, list tables or fetch a few rows) to confirm that the connection is working. The data transfer should be successful privately. If there are issues, double-check that the private endpoint shows as Connected/Approved on both sides and that no firewall or DNS issues exist.
By following this step-by-step guide, you can securely connect Microsoft Fabric Notebook to an Azure Database for PostgreSQL using Managed Private Endpoints. This setup ensures that all outbound traffic remains on the private network, providing enhanced security and performance. Each step is based on Microsoft’s official guidelines for Managed Private Endpoints in Microsoft Fabric and Azure PostgreSQL documentation. Following this checklist will ensure your Fabric environment can securely communicate with the Azure PostgreSQL database over a private link without exposing the database to the public internet.
Note: Fabric inbound traffic protection needs consideration as there are some restrictions that may not be intended. Review About private Links for secure access to Fabric - Microsoft Fabric | Microsoft Learn to understand the configuration and the experiences. If you choose to use the private link follow Set up and use private links for secure access to Fabric - Microsoft Fabric | Microsoft Learn
Contributors
Taisha Ferguson Sr Cloud Solution Architect @taferguson
Jen Sheerin Sr Cloud Solution Architect @jensheerin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.