How can I connect to the Postgres Flexible server to Azure Web App on Virtual Network from a different region.

Ashwin 0 Reputation points
2025-01-02T18:58:16.6733333+00:00

I have a Azure Postgres Flexible server hosted in SouthEast Asia and hosting the backend Azure Web App hosted on East US (Proximity to the Azure OpenAI models), here the Azure Web App is not able to connect to the Postgres Flexible server. I have created Private networks in both regions (SouthEast Asia and US East) and have set them as peering network. Any guidance will be helpful

Azure Database for PostgreSQL
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
1,040 questions
Azure Startups
Azure Startups
Azure: A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.Startups: Companies that are in their initial stages of business and typically developing a business model and seeking financing.
514 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Laxman Reddy Revuri 1,605 Reputation points Microsoft Vendor
    2025-01-04T00:59:11.67+00:00

    Hi @Ashwin
    Thanks for the question and using MS Q&A platform.
    To resolve the connectivity issue between your Azure Web App in East US and the PostgreSQL Flexible Server in SouthEast Asia, follow these steps:

    1.Verify VNet Peering Configuration

    Ensure that the VNet peering between the two regions is correctly set up:

    Allow Forwarded Traffic: Confirm that the peering configuration allows forwarded traffic. This setting is crucial for communication between resources in different VNets.

    2.Use Remote Gateways: If necessary, enable the option to use remote gateways.

    Check Firewall Settings

    Since your PostgreSQL server is likely configured for private access:

    Add Web App IP Addresses: Include the outbound IP addresses of your Azure Web App in the firewall rules of your PostgreSQL server. This can be done in the Azure Portal under the PostgreSQL server's networking settings.

    3.Allow Azure Services: Optionally enable "Allow Azure services and resources to access this server" to simplify connectivity.

    4.Enable VNet Integration for Your Web App

    Integrate your Azure Web App with the VNet where your PostgreSQL server resides:

    VNet Integration: Use Azure CLI or the Azure Portal to integrate your web app with the appropriate VNet. This enables private connectivity to your PostgreSQL server.

    1. Configure Connection Strings

    Make sure that your application uses the correct connection string format to connect to the PostgreSQL server:

    • Use the fully qualified server name and ensure SSL is enabled.
    Host=<your-server-name>.postgres.database.azure.com;Username=<your-admin-username>;Password=<your-password>;Database=<your-database-name>;SSL Mode=Require;
    

    References:
    Create and manage virtual networks with Private Link for Azure Database for PostgreSQL - Flexible Server by using the Azure portal.

    Troubleshoot a connectivity issue between two peered virtual networks

    Troubleshoot connection issues to Azure Database for PostgreSQL - Flexible Server

    Connect Azure Database for PostgreSQL - Flexible Server with the private access connectivity method


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.