How to connect to Azure PostgreSQL Server

In this article, we will see how to connect to Azure PostgreSQL Server from pgadmin or psql.

1. Steps to connect to Azure PostgreSQL server from pgadmin:

1. Connect to Azure portal, then click on Azure PostgreSQL Server. From left menu click on connection security. Then, provide name for your firewall, IP address as show below. Then click on Save.

How to connect to Azure PostgreSQL Server

2. Open pgadmin.
3. Then from left menu right click on Servers, select create and select Server as shown below.

4. Then, provide the Name for PostgreSQL server connection in General tab.

5. In connection tab provide the hostname/address, port number, Maintenance database, Username and password. Username should be like username@hostname as shown in the below image. Then, click on Save.

6. Then, you will see PostgreSQL server in the left side menu.

How to connect to Azure PostgreSQL Server

2. Steps to connect to Azure PostgreSQL server from psql:

We can do this from windows and Linux servers. But, should have already installed PostgreSQL-client or PostgreSQL server.

1. Connect to Azure PostgreSQL server from Linux terminal.

Connect to Linux and open terminal. Then, run the following command.

psql -U postgresqladmin@couponpostgresql1 -h couponpostgresql1.postgres.database.azure.com -d postgres

2. Connect to Azure PostgreSQL server from Windows Command prompt:

Open command prompt as administrator. Then navigate to psql.exe installation like below

cd C:\Program Files\PostgreSQL\14\bin

Then paste same we used for Linux terminal like below.

psql -U postgresqladmin@couponpostgresql1 -h couponpostgresql1.postgres.database.azure.com -d postgres

Lets verify we have connected to Azure PostgreSQL or not by running \du command. it shows few azure default users for PostrgeSQL.

So, in this article we have seen three methods to connect to Azure PostgreSQL server using pgadmin and psql from Windows and Linux terminal.