Azure Database for PostgreSQL: Quickstart

This guide will walk you through the steps to quickly set up and connect to an Azure Database for PostgreSQL server.

Prerequisites

Before you begin, ensure you have:

Step 1: Create an Azure Database for PostgreSQL server

Using the Azure portal

  1. Sign in to the Azure portal.
  2. In the search bar, type "Azure Database for PostgreSQL servers" and select it from the results.
  3. Click "Create".
  4. Select the "Single server" deployment option.
  5. Fill in the required details:
    • Subscription: Choose your Azure subscription.
    • Resource group: Select or create a resource group.
    • Server name: Enter a unique name for your PostgreSQL server.
    • Location: Choose the Azure region where you want to deploy your server.
    • PostgreSQL version: Select the desired PostgreSQL version (e.g., 11, 12, 13).
    • Compute + Storage: Configure your compute and storage requirements. For quickstart, you can choose a basic tier.
    • Admin username: Enter an administrator username (e.g., pgadmin).
    • Password: Enter and confirm a strong password.
  6. Click "Review + create", then "Create".
Tip: For a minimal setup, you can use the "Basic" pricing tier. You can scale up later as needed.

Step 2: Configure firewall rules

Allowing client connections

  1. Once your server is deployed, navigate to its resource page in the Azure portal.
  2. In the left-hand menu, under "Settings", click "Connection security".
  3. Under "Firewall rules", click "Add firewall rule".
  4. Provide a Rule name (e.g., AllowMyIP).
  5. Enter your Start IP and End IP addresses. To allow your current IP address, you can often click the "Add current client IP" button if available, or find your public IP address and enter it for both start and end.
  6. Click "Save".
Tip: For development purposes, you can set the start and end IP to 0.0.0.0 to allow all connections, but this is not recommended for production environments.

Step 3: Connect to the server

Using psql

  1. From the "Connection security" page of your PostgreSQL server in the Azure portal, find your Server name and Admin username.
  2. Open your terminal or command prompt.
  3. Use the psql command with your server details. Replace placeholders with your actual values:
    psql --host=.postgres.database.azure.com --user=@ --dbname=postgres --port=5432
  4. When prompted, enter the password you set during server creation.
  5. If the connection is successful, you will see the PostgreSQL prompt:
    postgres=>

Next Steps