Search code examples
postgresqlazurepgadmin-4vnetazure-data-studio

How to connect PGAdmin 4 to Postgres DB residing in Azure Virtual Network


Lots of similar questions on this but have not come across an answer for an "Azure Database for PostgreSQL flexible server" set up with Private Access (VNet Integration).

The Postgresql DB is used by an Azure Web App that queries it and displays data from one of the database tables on the web app's UI. Obvious case use, but I'm mentioning it as it's the reason why I set the connectivity method to "Private access (VNet Integration)", instead of "Public access" in Settings->Networking->Network Connectivity->Connectivity method; I did not want the database directly accessible from a public endpoint, only the web app's back end.

Setting the Database up resulted in adding a virtual network, a "privatelink.postgres.database.azure.com" Private DNS Zone and a Server which sits inside the virtual network, getting fed an ip address from the privatelink Zone.

But here's the thing... whilst I do not want it accessible from the outside, I do actually need to view the db tables, schema, data etc whilst I build it all, so I need to access it from an app run on my local computer in the office, so...well...from the outside. :-)

I can write to the database fine through my flask application, I can't view the tables, data etc.

I have tried using both the Azure Data Studio and pgAdmin 4 apps, but unsurprisingly I get the DNS resolution problem "Unable to connect to server: connection is bad: No such host is known".

This is an example of the same problem but with Public access, which give rise to "timeout expired" notifications, not "no such host is known".

How can i connect Azure postgres database to pgadmin as im getting time out error

I had read that I needed to set some firewall settings as in the link below from a year ago, but the page with the toggle to allow access settings to Azure services does not even exist on my Azure portal.

https://learn.microsoft.com/en-us/azure/postgresql/single-server/concepts-firewall-rules

There is a similar question here, but that points to changing the severs connectivity to publicly accessible:

How to connect to a DB in a Virtual Network in Azure

I'm lost...Any ideas?


Solution

  • First, this is deprecated https://learn.microsoft.com/en-us/azure/postgresql/single-server/concepts-firewall-rules Use the flexible server docs. To connect to an Azure Database for PostgreSQL flexible server with Private Access (VNet Integration) from your local computer, you can use a Point-to-Site (P2S) VPN connection. This allows you to connect to the virtual network that hosts your PostgreSQL server from your local computer. You can then use tools like Azure Data Studio or pgAdmin to connect to the database using the private IP address of the server. https://techcommunity.microsoft.com/t5/itops-talk-blog/step-by-step-creating-an-azure-point-to-site-vpn/ba-p/326264 Please do also check https://learn.microsoft.com/en-us/answers/questions/1300731/azure-database-for-postgresql-flexible-servers-wit