'Unable to create azure postgresql flexible server with azure-cli
I'm trying to create a postgresql database on azure with azure-cli. I set my default location with az configure --defaults location=WestEurope, then I created a resourcegroup, a vnet and a subnet. Now I want to create a flexible server for postgresql with
az postgres flexible-server create --name $SERVERNAME --vnet $VNET --subnet $DBSUBNET
--admin-user $DB_USER --admin-password $DB_PASSWORD --sku-name Standard_B1ms --tier Burstable --storage-size 1024 --tags "Billing=test" --version 13 --database-name $DB_NAME
but I get this error and the server is not created: The location of Vnet should be same as the location of the server.
My Vnet is obviously located in WestEurope, given my default location set before, and I can't understand how the location of any resource I create could be different from my default location. I even tried to add --location WestEurope to the command, but it produced the same result.
Solution 1:[1]
I tried to set the default location as West Europe through AZ CLI in Azure Cloud Shell:
az configure --defaults location=westeurope
To create the PostgreSQL Server and database in the specified default location:
az postgres flexible-server create --resource-group HariTestRG \
--name demoserver1205 --admin-user <username> --admin-password <your-password> \
--sku-name Standard_B1ms --tier Burstable --storage-size 1024 \
--tags "Billing=test" --version 13 \
--vnet myVnet --subnet mySubnet --database-name demopsqldb01 \
Result:

Private DNS Zone is created at the global level automatically by Azure while creating the Postgres SQL Server and the Virtual Network.
Note:
- After executing the default location command, you need to execute the remaining CLI commands without any error.
- If you got the error in between the execution of any other commands, then execute the default location config command again.
- Without interactive activity, cloud shell time out after 20 minutes and it runs on a temporary host provided on a per-session basis.
Updated Answer:
Here I created the VNet and Subnet in the resource group. Created the PostgreSQL Server and database with the existing VNet and Subnet through AZ CLI (using the above CLI Cmdlets - worked successfully):
Result:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |


