Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Azure Database for PostgreSQL with elastic clusters is a managed service that you use to run, manage, and scale highly available PostgreSQL databases in the cloud with a horizontal scale-out capability. You can use an Azure Resource Manager template (ARM template) to create an elastic clusters instance.
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.
Azure Resource Manager is the deployment and management service for Azure. It provides a management layer that enables you to create, update, and delete resources in your Azure account. You use management features, like access control, locks, and tags, to secure and organize your resources after deployment. To learn about Azure Resource Manager templates, see Template deployment overview.
Prerequisites
An Azure account with an active subscription. Create one for free.
Review the template
An Azure Database for PostgreSQL flexible server instance is the parent resource for a distributed database within a region. It provides the scope for management policies that apply to the cluster: firewall, users, roles, and configurations.
Create a elastic-cluster-template.json file and copy the following JSON script into it.
{
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"administratorLogin": {
"type": "string"
},
"administratorLoginPassword": {
"type": "securestring"
},
"location": {
"type": "string",
"defaultValue": "canadacentral"
},
"clusterName": {
"type": "string"
},
"serverEdition": {
"type": "string",
"defaultValue": "GeneralPurpose"
},
"storageSizeGB": {
"type": "int",
"defaultValue": 64
},
"haEnabled": {
"type": "string",
"defaultValue": "Disabled"
},
"availabilityZone": {
"type": "string",
"defaultValue": "1"
},
"backupRetentionDays": {
"type": "int",
"defaultValue": 7
},
"skuName": {
"type": "string",
"defaultValue": "Standard_D4ds_v5"
},
"clusterSize": {
"type": "int",
"defaultValue": 2
},
"guid": {
"type": "string",
"defaultValue": "[newGuid()]"
},
"firewallRules": {
"type": "object",
"defaultValue": {
"rules": [
{
"name": "AllowAll",
"startIPAddress": "0.0.0.0",
"endIPAddress": "255.255.255.255"
}
]
}
},
"network": {
"type": "object",
"defaultValue": { "publicNetworkAccess": "Enabled" }
}
},
"variables": {
"firewallRules": "[parameters('firewallRules').rules]"
},
"resources": [
{
"apiVersion": "2025-08-01",
"location": "[parameters('location')]",
"name": "[parameters('clusterName')]",
"properties": {
"createMode": "Default",
"version": "16",
"administratorLogin": "[parameters('administratorLogin')]",
"administratorLoginPassword": "[parameters('administratorLoginPassword')]",
"availabilityZone": "[parameters('availabilityZone')]",
"Storage": {
"StorageSizeGB": "[parameters('storageSizeGB')]",
"Autogrow": "Disabled"
},
"Network": "[if(empty(parameters('network')), json('null'), parameters('network'))]",
"Backup": {
"backupRetentionDays": "[parameters('backupRetentionDays')]",
"geoRedundantBackup": "Disabled"
},
"highAvailability": {
"mode": "[parameters('haEnabled')]"
},
"cluster": {
"clusterSize": "[parameters('clusterSize')]"
}
},
"sku": {
"name": "[parameters('skuName')]",
"tier": "[parameters('serverEdition')]"
},
"type": "Microsoft.DBforPostgreSQL/flexibleServers"
},
{
"condition": "[greater(length(variables('firewallRules')), 0)]",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-08-01",
"name": "[concat('firewallRules-', parameters('guid'), '-', copyIndex())]",
"copy": {
"count": "[if(greater(length(variables('firewallRules')), 0), length(variables('firewallRules')), 1)]",
"mode": "Serial",
"name": "firewallRulesIterator"
},
"dependsOn": [
"[concat('Microsoft.DBforPostgreSQL/flexibleServers/', parameters('clusterName'))]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.DBforPostgreSQL/flexibleServers/firewallRules",
"name": "[concat(parameters('clusterName'),'/',variables('firewallRules')[copyIndex()].name)]",
"apiVersion": "2025-08-01",
"properties": {
"StartIpAddress": "[variables('firewallRules')[copyIndex()].startIPAddress]",
"EndIpAddress": "[variables('firewallRules')[copyIndex()].endIPAddress]"
}
}
]
}
}
}
]
}
These resources are defined in the template:
Deploy the template
Select Try it from the following PowerShell code block to open Azure Cloud Shell.
$clusterName = Read-Host -Prompt "Enter a name for the new Azure Database for PostgreSQL flexible server elastic cluster instance"
$resourceGroupName = Read-Host -Prompt "Enter a name for the new resource group where the elastic cluster will exist"
$adminUser = Read-Host -Prompt "Enter the Azure Database for PostgreSQL flexible server elastic cluster instance's administrator account name"
$adminPassword = Read-Host -Prompt "Enter the administrator password" -AsSecureString
# New-AzResourceGroup -Name $resourceGroupName -Location <AZURE_LOCATION> Use this command when you need to create a new resource group for your deployment
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName `
-TemplateFile "elastic-cluster-template.json" `
-clusterName $clusterName `
-administratorLogin $adminUser `
-administratorLoginPassword $adminPassword
Read-Host -Prompt "Press [ENTER] to continue ..."
Review deployed resources
Follow these steps to verify if your Azure Database for PostgreSQL flexible server elastic cluster was created.
- In the Azure portal, search for and select Azure Database for PostgreSQL flexible servers.
- In the database list, select your new server to view the Overview page to manage your elastic cluster.
Next Steps
Keep this resource group and the elastic cluster if you want to use it to continue with the next suggested steps listed in the Related content section. The next steps show you how to use elastic clusters with different application sharding models and designs.
Clean up resources
When you are finished with your elastic cluster environment, you can delete your elastic cluster resource:
To delete the elastic cluster:
In the portal, select the resource group you want to delete.
- Select Delete resource group.
- To confirm the deletion, type the name of the resource group.