# How to use Flexible Server in Azure Database for PostgreSQL

# Highly configurable PostgreSQL server

Azure Database for PostgreSQL (opens new window) provides a managed PostgreSQL server that allows you to focus on using PostgreSQL, instead of focusing on managing your database server. You can choose to run Azure Database for PostgreSQL as a Single server (opens new window), which is designed to handle most of the database management functions such as patching, backups, high availability, and security with minimal user configuration and control. You can also create an Azure Database for PostgreSQL with a Flexible Server (opens new window), which allows for more configuration and control of the database server.

In this post, we'll create an Azure Database for PostgreSQL with the Flexible Server option.

# Prerequisites

If you want to follow along, you'll need the following:

# Create a Flexible PostgreSQL server

We will use the Azure portal to create an Azure Database for PostgreSQL and connect to it using the Azure Cloud Shell (opens new window).

  1. Go to the Azure portal (opens new window)

  2. Click the Create a resource button (the plus-sign in the top left corner)

  3. Search for database for postgresql, select the "Azure Database for PostgreSQL" result and click Create

    1. This shows the Select Azure Database for PostgreSQL deployment option screen

    (Azure Database for PostgreSQL server options)

    1. Click the Create button under Flexible server. This opens the Flexible server blade
    2. Select a Resource Group
    3. Fill in a Name for the server
    4. Select a Region
    5. Choose a Workload type. This determines the compute and storage option that you use. Flexible server offers the option to use Burstable compute, which ramps up the server CPU only when needed. This is great for non-production workloads

    (Flexible server creation options)

    1. You can configure compute and storage in more detail, by clicking on configure server. This brings up the Compute + storage blade. This allows you to set the size of the VM on which the server runs, and the storage size and performance on which your data sits. In this blade, you can also configure the server backups and make them geo-redundant (you can only choose this when you don't use a burstable compute tier)

    (Compute + storage options)

    1. Next, choose the availability zone you want the VM(s) that runs the PostgreSQL server to use
    2. Leave the High Availability setting unchecked. You should use this when you want additional availability precautions within availability zones, for production workloads. As we are using the burstable compute tier for development workloads, we don't need this
    3. Leave the PostgreSQL version to the selected version
    4. Fill in an Admin username that you will use to connect to the server
    5. Type a Password for the admin user and confirm the password
    6. Select Next:Networking

    (Configure networking options)

    1. Flexible server can put the server in a virtual network, so that it is not exposed to the internet. You can also allow the server to be accessed through the internet and secure it with a firewall. This is what we will do. Select Public access (allowed IP addresses)
    2. Under Firewall rules, select the Add 0.0.0.0 - 255.255.255.255 link to add a firewall rule that allows all IP addresses to access the server. You should never use this firewall rule for a real-world application, but you can use it for development or demo purposes
    3. Click Review + create and then Create to create the server

When the Azure Database for PostgreSQL server is created, navigate to it in the Azure portal. In the overview blade, you'll see that you can stop the server. This is a feature of Flexible server. Stopping the server can save you a lot of money when you don't use it.

(Stop the server from the Azure portal)

You can use the Azure Database for PostgreSQL server with your tool of choice. We will use the Azure Cloud Shell to connect to it. Azure Cloud Shell comes with the psql.exe tool preinstalled, through which we can use the PostgreSQL server.

  1. Go to https://shell.azure.com/ (opens new window)
  2. Execute the following command, and replace the servername and username with your own
    psql -h servername.postgres.database.azure.com -U username -p 5432 -d postgres
1

That's it. We are now connected to the Azure Database for PostgreSQL flexible server.

(Connected to the flexible server from the Azure Cloud Shell)

# Conclusion

The Flexible server (opens new window) option for Azure Database for PostgreSQL (opens new window) allows you to customize high availability, maintenance windows, use burstable compute, and stop and start the server. Go and check it out!