Deli putem


Quickstart: Use the az postgres up command 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 enables you to run, manage, and scale highly available PostgreSQL databases in the cloud. The Azure CLI is used to create and manage Azure resources from the command line or in scripts. This quickstart shows you how to use the az postgres up command to create an Azure Database for PostgreSQL server using the Azure CLI. In addition to creating the server, the az postgres up command creates a sample database, a root user in the database, opens the firewall for Azure services, and creates default firewall rules for the client computer. These defaults help to expedite the development process.

If you don't have an Azure subscription, create an Azure free account before you begin.

Create an Azure Database for PostgreSQL server

Prerequisites

Launch Azure Cloud Shell

The Azure Cloud Shell is a free interactive shell that you can use to run the steps in this article. It has common Azure tools preinstalled and configured to use with your account.

To open the Cloud Shell, just select Try it from the upper right corner of a code block. You can also launch Cloud Shell in a separate browser tab by going to https://shell.azure.com.

When Cloud Shell opens, verify that Bash is selected for your environment. Subsequent sessions will use Azure CLI in a Bash environment, Select Copy to copy the blocks of code, paste it into the Cloud Shell, and press Enter to run it.

Sign in to Azure

Cloud Shell is automatically authenticated under the initial account signed-in with. Use the following script to sign in using a different subscription, replacing <Subscription ID> with your Azure Subscription ID. If you don't have an Azure subscription, create an Azure free account before you begin.

subscription="<subscriptionId>" # add subscription here

az account set -s $subscription # ...or use 'az login'

For more information, see set active subscription or log in interactively

Install the db-up extension. If an error is returned, ensure you have installed the latest version of the Azure CLI. See Install Azure CLI.

az extension add --name db-up

Create an Azure Database for PostgreSQL server using the following command:

az postgres up

The server is created with the following default values (unless you manually override them):

Setting Default value Description
server-name System generated A unique name that identifies your Azure Database for PostgreSQL server.
resource-group System generated A new Azure resource group.
sku-name GP_Gen5_2 The name of the sku. Follows the convention {pricing tier}_{compute generation}_{vCores} in shorthand. The default is a General Purpose Gen5 server with 2 vCores. See our pricing page for more information about the tiers.
backup-retention 7 How long a backup is retained. Unit is days.
geo-redundant-backup Disabled Whether geo-redundant backups should be enabled for this server or not.
location westus2 The Azure location for the server.
ssl-enforcement Disabled Whether TLS/SSL should be enabled or not for this server.
storage-size 5120 The storage capacity of the server (unit is megabytes).
version 10 The PostgreSQL major version.
admin-user System generated The username for the administrator.
admin-password System generated The password of the administrator user.

Note

For more information about the az postgres up command and its additional parameters, see the Azure CLI documentation.

Once your server is created, it comes with the following settings:

  • A firewall rule called "devbox" is created. The Azure CLI attempts to detect the IP address of the machine the az postgres up command is run from and allows that IP address.
  • "Allow access to Azure services" is set to ON. This setting configures the server's firewall to accept connections from all Azure resources, including resources not in your subscription.
  • An empty database named "sampledb" is created
  • A new user named "root" with privileges to "sampledb" is created

Note

Azure Database for PostgreSQL communicates over port 5432. When connecting from within a corporate network, outbound traffic over port 5432 may not be allowed by your network's firewall. Have your IT department open port 5432 to connect to your server.

Get the connection information

After the az postgres up command is completed, a list of connection strings for popular programming languages is returned to you. These connection strings are pre-configured with the specific attributes of your newly created Azure Database for PostgreSQL server.

You can use the az postgres show-connection-string command to list these connection strings again.

Clean up resources

Clean up all resources you created in the quickstart using the following command. This command deletes the Azure Database for PostgreSQL server and the resource group.

az postgres down --delete-group

If you would just like to delete the newly created server, you can run az postgres down command.

az postgres down

Next steps