Lesson 3 of 4 · Azure Database Administration

Azure Database for PostgreSQL and MySQL

Running open source PostgreSQL and MySQL as managed Flexible Servers: compute tiers, high availability, read replicas, backups, networking, and engine specifics.

Beginner 10 sections 6 min read

Managed open source databases

Azure Database for PostgreSQL and Azure Database for MySQL run the open source engines as managed services. Microsoft handles the servers, patching, backups, and high availability, and you work with the PostgreSQL or MySQL you already know.

Both run as a Flexible Server: one managed server that hosts one or more databases. It's called flexible because, compared with older managed options, it gives the DBA more control:

  • Choose the maintenance window when patches are applied.
  • Tune hundreds of engine settings, called server parameters.
  • Pick which availability zone the server runs in, and where its standby goes.
  • Stop and start the server to save money when it isn't needed.

The two services work almost the same way, so this lesson covers them together and points out where they differ.

Compute and storage

A Flexible Server's size comes from its compute tier and size, plus its storage:

Compute tierDesigned forGood to know
BurstableDevelopment, testing, and light workloadsThe cheapest tier. It runs at a low baseline and builds up credits to burst when busy. Doesn't support high availability.
General PurposeMost production workloadsA balanced amount of memory per vCore.
Memory Optimized (PostgreSQL) or Business Critical (MySQL)Demanding, memory-hungry workloadsMore memory per vCore, for large caches and heavy query loads.

Storage is sized separately. It can be set to grow automatically when it gets full, but it can't shrink, so start modestly. Faster storage performance (IOPS) generally comes with larger or premium storage options.

High availability, replicas, and backups

PRIMARY REGION PrimaryStandby Zone 1Zone 2 synchronous Automated backups up to 35 days, optionally copied to another region ANOTHER REGION Read replica asynchronous read-only queries, and a disaster recovery option
High availability (zone-redundant or same-zone)
Adds a standby server that receives every change synchronously and takes over automatically if the primary fails, with no committed data lost. Put the standby in another availability zone (zone-redundant) to survive a data center failure, or in the same zone for lower latency. The standby can't be queried; it only waits to take over, and it doubles the compute cost.
Read replicas
Read-only copies, updated asynchronously, in the same region or another one. They take reporting queries off the primary, and a replica in another region can be promoted to become the primary in a regional disaster.
Automated backups
Taken automatically, with point-in-time restore for up to 35 days (7 days by default). With geo-redundant backup storage, backups are also copied to another region, so a server can be restored there with geo-restore.

Networking

When you create a Flexible Server, you choose how applications reach it:

  • Public access: the server has a public address, protected by firewall rules that allow only listed IP addresses. Private endpoints can be added for private connections.
  • Private access (virtual network integration): the server lives inside your own virtual network and has no public address at all.

Decide this up front: it's hard to change after the server is created. Production databases should almost always be reachable only privately. Connections are encrypted with TLS by default.

PostgreSQL specifics

Extensions
PostgreSQL's power comes from its extensions, such as PostGIS for geographic data, pgvector for AI vector search, and pg_stat_statements for query statistics. On Azure, an extension must first be allowed with the azure.extensions server parameter, then created in the database.
Connection pooling
PostgreSQL starts a separate process for every connection, so thousands of short connections can overwhelm it. Flexible Server includes PgBouncer, a connection pooler, which you can switch on with a server parameter.
Query Store and intelligent tuning
Azure's Query Store for PostgreSQL records query performance over time, and intelligent tuning can recommend indexes and settings.
Major version upgrades
Moving to a new major version, such as from PostgreSQL 15 to 16, can be done in place, with some downtime, after testing on a copy first.
# allow two extensions on the server
$ az postgres flexible-server parameter set --resource-group rg-sales \
    --server-name kofi-pg-01 --name azure.extensions --value vector,postgis

-- then, connected to the database, create one
CREATE EXTENSION vector;

MySQL specifics

Slow query log
Records queries that take longer than a threshold you set, the classic first step for finding MySQL performance problems. Logs can be sent to Azure Monitor for analysis.
Server parameters
Familiar MySQL settings, such as max_connections and the InnoDB buffer pool size, are set through Azure rather than a my.cnf file, since there's no access to the server's files.
Replication and migration
Besides read replicas, Flexible Server supports replicating from an external MySQL server into Azure, which is one way to migrate with little downtime.

Creating and connecting

With the Azure CLI, creating a production PostgreSQL server with zone-redundant high availability, and a small MySQL server for development, looks like this:

# PostgreSQL 16, General Purpose, 2 vCores, with a standby in another zone
$ az postgres flexible-server create --name kofi-pg-01 --resource-group rg-sales \
    --location eastus --tier GeneralPurpose --sku-name Standard_D2ds_v5 \
    --storage-size 128 --version 16 --high-availability ZoneRedundant \
    --admin-user pgadmin --admin-password "<strong-password>"

# MySQL 8.0 on the low-cost Burstable tier, for development
$ az mysql flexible-server create --name kofi-mysql-01 --resource-group rg-sales \
    --location eastus --tier Burstable --sku-name Standard_B1ms \
    --storage-size 32 --version 8.0.21 \
    --admin-user mysqladmin --admin-password "<strong-password>"

# stop the development server overnight to save money
$ az mysql flexible-server stop --name kofi-mysql-01 --resource-group rg-sales

Then connect with the usual tools, using the server's Azure address:

$ psql "host=kofi-pg-01.postgres.database.azure.com dbname=postgres user=pgadmin sslmode=require"
$ mysql -h kofi-mysql-01.mysql.database.azure.com -u mysqladmin -p

Compared with Azure SQL

Azure SQL DatabaseAzure Database for PostgreSQL or MySQL
EngineSQL Server (T-SQL)Open source PostgreSQL or MySQL
License costIncluded in the price; can be reduced with the Azure Hybrid BenefitNone: the engines are free
SizingDTU or vCore, General Purpose, Business Critical, or HyperscaleBurstable, General Purpose, or a high-memory tier
ServerlessYes, with auto-pauseNo, but servers can be stopped and started
High availabilityBuilt in, with optional zone redundancyOptional standby, in the same zone or another zone
Engine settingsMostly managed by MicrosoftMany server parameters you can tune

In practice: the Black Friday connection storm

Kofi's online store runs on Azure Database for PostgreSQL. On Black Friday, the application scales out from 10 to 60 servers, each opening 20 database connections: 1,200 in total, far more than the server allows. New connections start failing just as sales peak.

Every PostgreSQL connection is a separate process using memory, so simply raising the limit would make things worse. Instead, Kofi switches on the built-in PgBouncer and points the application at its port, 6432. PgBouncer hands a small pool of real database connections to thousands of application connections in turn, and the errors stop. The next week, Kofi also moves the hourly sales dashboard to a read replica, so reporting no longer competes with checkout.

Key takeaways

  • Azure Database for PostgreSQL and MySQL run the open source engines as managed Flexible Servers, with control over maintenance windows, parameters, zones, and stop and start.
  • Choose a compute tier: Burstable for development, General Purpose for most production, or a high-memory tier for demanding workloads. Storage can grow but not shrink.
  • Add a zone-redundant standby for high availability, read replicas for reporting and regional recovery, and geo-redundant backups for geo-restore.
  • Choose public or private access at creation, and keep production private.
  • PostgreSQL brings extensions and built-in PgBouncer; MySQL brings the slow query log and familiar server parameters.