Delen via


Quickstart: Use an ARM template to create an Azure Database for PostgreSQL - single server

APPLIES TO: Azure Database for PostgreSQL - Single Server

Important

Azure Database for PostgreSQL - Single Server is on the retirement path. We strongly recommend that you upgrade to Azure Database for PostgreSQL - Flexible Server. For more information about migrating to Azure Database for PostgreSQL - Flexible Server, see What's happening to Azure Database for PostgreSQL Single Server?.

Azure Database for PostgreSQL is a managed service that you use to run, manage, and scale highly available PostgreSQL databases in the cloud. In this quickstart, you use an Azure Resource Manager template (ARM template) to create an Azure Database for PostgreSQL - single server in the Azure portal, PowerShell, or Azure CLI.

An Azure Resource Manager template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. The template uses declarative syntax. You describe your intended deployment without writing the sequence of programming commands to create the deployment.

If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. The template will open in the Azure portal.

Button to deploy the Resource Manager template to Azure.

Prerequisites

APPLIES TO: Azure Database for PostgreSQL - Single Server

Important

Azure Database for PostgreSQL - Single Server is on the retirement path. We strongly recommend that you upgrade to Azure Database for PostgreSQL - Flexible Server. For more information about migrating to Azure Database for PostgreSQL - Flexible Server, see What's happening to Azure Database for PostgreSQL Single Server?.

An Azure account with an active subscription. Create one for free.

Review the template

You create an Azure Database for PostgreSQL server with a configured set of compute and storage resources. To learn more, see Pricing tiers in Azure Database for PostgreSQL - Single Server. You create the server within an Azure resource group.

The template used in this quickstart is from Azure Quickstart Templates.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.26.54.24096",
      "templateHash": "16694921643873529380"
    }
  },
  "parameters": {
    "serverName": {
      "type": "string",
      "metadata": {
        "description": "Server Name for Azure Database for PostgreSQL"
      }
    },
    "administratorLogin": {
      "type": "string",
      "minLength": 1,
      "metadata": {
        "description": "Database administrator login name"
      }
    },
    "administratorLoginPassword": {
      "type": "securestring",
      "minLength": 8,
      "metadata": {
        "description": "Database administrator password"
      }
    },
    "skuCapacity": {
      "type": "int",
      "defaultValue": 2,
      "metadata": {
        "description": "Azure Database for PostgreSQL compute capacity in vCores (2,4,8,16,32)"
      }
    },
    "skuName": {
      "type": "string",
      "defaultValue": "GP_Gen5_2",
      "metadata": {
        "description": "Azure Database for PostgreSQL sku name "
      }
    },
    "skuSizeMB": {
      "type": "int",
      "defaultValue": 51200,
      "metadata": {
        "description": "Azure Database for PostgreSQL Sku Size "
      }
    },
    "skuTier": {
      "type": "string",
      "defaultValue": "GeneralPurpose",
      "allowedValues": [
        "Basic",
        "GeneralPurpose",
        "MemoryOptimized"
      ],
      "metadata": {
        "description": "Azure Database for PostgreSQL pricing tier"
      }
    },
    "skuFamily": {
      "type": "string",
      "defaultValue": "Gen5",
      "metadata": {
        "description": "Azure Database for PostgreSQL sku family"
      }
    },
    "postgresqlVersion": {
      "type": "string",
      "defaultValue": "11",
      "allowedValues": [
        "9.5",
        "9.6",
        "10",
        "10.0",
        "10.2",
        "11"
      ],
      "metadata": {
        "description": "PostgreSQL version"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    },
    "backupRetentionDays": {
      "type": "int",
      "defaultValue": 7,
      "metadata": {
        "description": "PostgreSQL Server backup retention days"
      }
    },
    "geoRedundantBackup": {
      "type": "string",
      "defaultValue": "Disabled",
      "metadata": {
        "description": "Geo-Redundant Backup setting"
      }
    },
    "virtualNetworkName": {
      "type": "string",
      "defaultValue": "azure_postgresql_vnet",
      "metadata": {
        "description": "Virtual Network Name"
      }
    },
    "subnetName": {
      "type": "string",
      "defaultValue": "azure_postgresql_subnet",
      "metadata": {
        "description": "Subnet Name"
      }
    },
    "virtualNetworkRuleName": {
      "type": "string",
      "defaultValue": "AllowSubnet",
      "metadata": {
        "description": "Virtual Network RuleName"
      }
    },
    "vnetAddressPrefix": {
      "type": "string",
      "defaultValue": "10.0.0.0/16",
      "metadata": {
        "description": "Virtual Network Address Prefix"
      }
    },
    "subnetPrefix": {
      "type": "string",
      "defaultValue": "10.0.0.0/16",
      "metadata": {
        "description": "Subnet Address Prefix"
      }
    }
  },
  "variables": {
    "firewallrules": [
      {
        "Name": "rule1",
        "StartIpAddress": "0.0.0.0",
        "EndIpAddress": "255.255.255.255"
      },
      {
        "Name": "rule2",
        "StartIpAddress": "0.0.0.0",
        "EndIpAddress": "255.255.255.255"
      }
    ]
  },
  "resources": [
    {
      "type": "Microsoft.DBforPostgreSQL/servers/virtualNetworkRules",
      "apiVersion": "2017-12-01",
      "name": "[format('{0}/{1}', parameters('serverName'), parameters('virtualNetworkRuleName'))]",
      "properties": {
        "virtualNetworkSubnetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnetName'))]",
        "ignoreMissingVnetServiceEndpoint": true
      },
      "dependsOn": [
        "[resourceId('Microsoft.DBforPostgreSQL/servers', parameters('serverName'))]",
        "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnetName'))]"
      ]
    },
    {
      "type": "Microsoft.Network/virtualNetworks",
      "apiVersion": "2023-09-01",
      "name": "[parameters('virtualNetworkName')]",
      "location": "[parameters('location')]",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "[parameters('vnetAddressPrefix')]"
          ]
        }
      }
    },
    {
      "type": "Microsoft.Network/virtualNetworks/subnets",
      "apiVersion": "2023-09-01",
      "name": "[format('{0}/{1}', parameters('virtualNetworkName'), parameters('subnetName'))]",
      "properties": {
        "addressPrefix": "[parameters('subnetPrefix')]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]"
      ]
    },
    {
      "type": "Microsoft.DBforPostgreSQL/servers",
      "apiVersion": "2017-12-01",
      "name": "[parameters('serverName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('skuName')]",
        "tier": "[parameters('skuTier')]",
        "capacity": "[parameters('skuCapacity')]",
        "size": "[format('{0}', parameters('skuSizeMB'))]",
        "family": "[parameters('skuFamily')]"
      },
      "properties": {
        "createMode": "Default",
        "version": "[parameters('postgresqlVersion')]",
        "administratorLogin": "[parameters('administratorLogin')]",
        "administratorLoginPassword": "[parameters('administratorLoginPassword')]",
        "storageProfile": {
          "storageMB": "[parameters('skuSizeMB')]",
          "backupRetentionDays": "[parameters('backupRetentionDays')]",
          "geoRedundantBackup": "[parameters('geoRedundantBackup')]"
        },
        "sslEnforcement": "Enabled",
        "minimalTlsVersion": "TLS1_2"
      }
    },
    {
      "copy": {
        "name": "firewallRules",
        "count": "[length(variables('firewallrules'))]",
        "mode": "serial",
        "batchSize": 1
      },
      "type": "Microsoft.DBforPostgreSQL/servers/firewallRules",
      "apiVersion": "2017-12-01",
      "name": "[format('{0}/{1}', parameters('serverName'), variables('firewallrules')[copyIndex()].Name)]",
      "properties": {
        "startIpAddress": "[variables('firewallrules')[copyIndex()].StartIpAddress]",
        "endIpAddress": "[variables('firewallrules')[copyIndex()].EndIpAddress]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.DBforPostgreSQL/servers', parameters('serverName'))]"
      ]
    }
  ],
  "outputs": {
    "name": {
      "type": "string",
      "value": "[parameters('serverName')]"
    },
    "resourceId": {
      "type": "string",
      "value": "[resourceId('Microsoft.DBforPostgreSQL/servers', parameters('serverName'))]"
    },
    "resourceGroupName": {
      "type": "string",
      "value": "[resourceGroup().name]"
    },
    "location": {
      "type": "string",
      "value": "[parameters('location')]"
    }
  }
}

The template defines five Azure resources:

More Azure Database for PostgreSQL template samples can be found in Azure Quickstart Templates.

Deploy the template

APPLIES TO: Azure Database for PostgreSQL - Single Server

Important

Azure Database for PostgreSQL - Single Server is on the retirement path. We strongly recommend that you upgrade to Azure Database for PostgreSQL - Flexible Server. For more information about migrating to Azure Database for PostgreSQL - Flexible Server, see What's happening to Azure Database for PostgreSQL Single Server?.

Select the following link to deploy the Azure Database for PostgreSQL server template in the Azure portal:

Button to deploy the Resource Manager template to Azure.

On the Deploy Azure Database for PostgreSQL with VNet page:

  1. For Resource group, select Create new, enter a name for the new resource group, and select OK.

  2. If you created a new resource group, select a Location for the resource group and the new server.

  3. Enter a Server Name, Administrator Login, and Administrator Login Password.

  4. Change the other default settings if you want:

    • Subscription: the Azure subscription you want to use for the server.
    • Sku Capacity: the vCore capacity, which can be 2 (the default), 4, 8, 16, 32, or 64.
    • Sku Name: the SKU tier prefix, SKU family, and SKU capacity, joined by underscores, such as B_Gen5_1, GP_Gen5_2 (the default), or MO_Gen5_32.
    • Sku Size MB: the storage size, in megabytes, of the Azure Database for PostgreSQL server (default 51200).
    • Sku Tier: the deployment tier, such as Basic, GeneralPurpose (the default), or MemoryOptimized.
    • Sku Family: Gen4 or Gen5 (the default), which indicates hardware generation for server deployment.
    • PostgreSQL Version: the version of PostgreSQL server to deploy, such as 9.5, 9.6, 10, or 11 (the default).
    • Backup Retention Days: the desired period for geo-redundant backup retention, in days (default 7).
    • Geo Redundant Backup: Enabled or Disabled (the default), depending on geo-disaster recovery (Geo-DR) requirements.
    • Virtual Network Name: the name of the virtual network (default azure_postgresql_vnet).
    • Subnet Name: the name of the subnet (default azure_postgresql_subnet).
    • Virtual Network Rule Name: the name of the virtual network rule allowing the subnet (default AllowSubnet).
    • Vnet Address Prefix: the address prefix for the virtual network (default 10.0.0.0/16).
    • Subnet Prefix: the address prefix for the subnet (default 10.0.0.0/16).
  5. Read the terms and conditions, and then select I agree to the terms and conditions stated above.

  6. Select Purchase.

Review deployed resources

APPLIES TO: Azure Database for PostgreSQL - Single Server

Important

Azure Database for PostgreSQL - Single Server is on the retirement path. We strongly recommend that you upgrade to Azure Database for PostgreSQL - Flexible Server. For more information about migrating to Azure Database for PostgreSQL - Flexible Server, see What's happening to Azure Database for PostgreSQL Single Server?.

Follow these steps to see an overview of your new Azure Database for PostgreSQL server:

  1. In the Azure portal, search for and select Azure Database for PostgreSQL servers.

  2. In the database list, select your new server. The Overview page for your new Azure Database for PostgreSQL server appears.

Exporting ARM template from the portal

You can export an ARM template from the Azure portal. There are two ways to export a template:

When exporting the template, in the "properties":{ } section of the PostgreSQL server resource you will notice that administratorLogin and administratorLoginPassword will not be included for security reasons. You MUST add these parameters to your template before deploying the template or the template will fail.

"resources": [
    {
      "type": "Microsoft.DBforPostgreSQL/servers",
      "apiVersion": "2017-12-01",
      "name": "[parameters('servers_name')]",
      "location": "southcentralus",
      "sku": {
                "name": "B_Gen5_1",
                "tier": "Basic",
                "family": "Gen5",
                "capacity": 1
            },
      "properties": {
        "administratorLogin": "[parameters('administratorLogin')]",
        "administratorLoginPassword": "[parameters('administratorLoginPassword')]",

Clean up resources

When it's no longer needed, delete the resource group, which deletes the resources in the resource group.

APPLIES TO: Azure Database for PostgreSQL - Single Server

Important

Azure Database for PostgreSQL - Single Server is on the retirement path. We strongly recommend that you upgrade to Azure Database for PostgreSQL - Flexible Server. For more information about migrating to Azure Database for PostgreSQL - Flexible Server, see What's happening to Azure Database for PostgreSQL Single Server?.

  1. In the Azure portal, search for and select Resource groups.

  2. In the resource group list, choose the name of your resource group.

  3. In the Overview page of your resource group, select Delete resource group.

  4. In the confirmation dialog box, type the name of your resource group, and then select Delete.

Next steps

For a step-by-step tutorial that guides you through the process of creating a template, see: