Skip to main content

Azure Database for PostgreSQL & MySQL

Azure Database for PostgreSQL

Deployment Options

OptionDescription
Flexible ServerRecommended. Zone-redundant HA, burstable compute, stop/start.
Single ServerDeprecated — migrate to Flexible Server

Key Features

  • Versions: PostgreSQL 13, 14, 15, 16
  • Compute tiers: Burstable, General Purpose, Memory Optimized
  • Storage: Up to 16 TB, auto-grow supported
  • HA: Zone-redundant with automatic failover
  • Read replicas: Up to 5 replicas, cross-region supported
  • Extensions: pg_stat_statements, pgcrypto, PostGIS, many more

Connection Example

-- Connect via psql
psql "host=myserver.postgres.database.azure.com port=5432 dbname=mydb user=myadmin password=<YOUR_PASSWORD> sslmode=require"

-- Check version
SELECT version();

-- Enable useful extensions
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
CREATE EXTENSION IF NOT EXISTS pgcrypto;
🎯 Exam Focus

For DP-300, know that Flexible Server is the recommended deployment for PostgreSQL. Single Server is deprecated. Key differentiator: Flexible Server supports stop/start capability for cost savings.

Azure Database for MySQL

Deployment Options

OptionDescription
Flexible ServerRecommended. Same-zone and zone-redundant HA.
Single ServerDeprecated — migrate to Flexible Server

Key Features

  • Versions: MySQL 5.7, 8.0
  • Compute tiers: Burstable (B-series), General Purpose, Business Critical
  • Storage: Up to 16 TB, auto-grow
  • HA: Same-zone and zone-redundant options
  • Read replicas: Up to 5, cross-region supported
  • Data-in replication: Replicate from external MySQL to Azure

MySQL Performance Tuning Parameters

-- Key server parameters to tune
-- slow_query_log = ON
-- long_query_time = 2
-- innodb_buffer_pool_size = ~70-80% of available memory
-- max_connections = based on tier (default varies)

-- Check slow query status
SHOW VARIABLES LIKE 'slow_query_log';
SHOW VARIABLES LIKE 'long_query_time';
🏢 Real-World DBA Note

When migrating from on-prem MySQL, use Azure Database Migration Service (DMS) for minimal downtime. For PostgreSQL, you can also use pg_dump/pg_restore for smaller databases.

Comparison: PostgreSQL vs MySQL on Azure

FeaturePostgreSQL FlexibleMySQL Flexible
HAZone-redundantSame-zone + Zone-redundant
Max Storage16 TB16 TB
Read ReplicasUp to 5Up to 5
Stop/Start
Backup Retention7-35 days7-35 days
VNET Integration
Private Link

Anti-Patterns

  • "Use Single Server because it's cheaper." PostgreSQL Single Server is deprecated — retirement on the roadmap. New deployments must be Flexible Server. MySQL Single Server is also retired. Picking Single Server today = a forced migration in months.
  • "Burstable tier for production." Burstable banks credits when idle and burns them on spikes. Steady production load drains credits within hours and the DB throttles to baseline (~5–10 % of vCore). Use General Purpose for any sustained workload.
  • "Same-zone HA is good enough." Same-zone protects against host failures, not zone outages. For 99.99 % SLA you must pick zone-redundant HA (paid only for GP+ tier, separate zone for standby).
  • "Read replicas count as DR." They're async, in any region, and not promoted automatically. They protect read scale, not RTO. For DR, combine with backups and a documented promotion runbook.
  • "Just allow 0.0.0.0/0 in firewall to test." That setting replaces IP-rule validation with "allow any Azure service in any tenant." It's the single most common Defender for Cloud finding on Flexible Server.
  • "PostgreSQL extensions — install whatever I need." Only allow-listed extensions load (azure.extensions server parameter). pg_repack, pgvector, postgis are common ones, but pg_cron requires Flexible Server and a parameter restart.
⚠️ Watch Out

Storage auto-grow on Flexible Server is one-way. It expands but never shrinks. Over-provisioning costs you forever. Right-size at create or rebuild via dump/restore.


Migration Between Options

From → ToPathCost
Single Server (PG/MySQL) → Flexible ServerAzure Database Migration Service (online or offline)Plan for it now — Single Server retiring; minimal downtime via online mode
On-prem PostgreSQL → Flexible ServerDMS (online), pg_dump/pg_restore (offline), or logical replicationLogical replication = lowest downtime
Burstable → General PurposeOnline tier scaleBrief reconnect; gain non-burst CPU
GP → Memory OptimizedOnline tier scaleBrief reconnect; for cache-heavy / OLAP workloads
Same-zone HA → Zone-redundant HARecreate — cannot change in placeBackup + restore; downtime window required
Public access → Private endpoint / VNet-injectedRecreate (PG Flexible) or transition (MySQL)Plan IP space; private DNS zone; firewall update on app side
Flexible Server → Cosmos DB for PostgreSQLCitus extension; reshape schema for distributedSignificant rewrite; only for horizontal-scale needs
Single-region → Geo-Redundant BackupToggle backup option (only at create for some tiers)Doubles backup storage cost; gain cross-region restore

Most-expensive moves: same-zone HA → zone-redundant (forces recreate) and public → private (network rework).


Real Scenarios

  1. Greenfield SaaS, multi-tenant Postgres, 99.99 % SLAPG Flexible Server, GP tier, zone-redundant HA, private endpoint, geo-redundant backup. Driver: SLA + tenant isolation. Trade-off: 2× compute cost for HA standby.
  2. Migrating WordPress + 50 plugins from on-prem MySQL 5.7MySQL Flexible Server, GP tier, same-zone HA, public access with FW rules. Driver: simple LAMP stack. Trade-off: same-zone HA = lower SLA but half the cost.
  3. Analytical workload, 8 TB Postgres, weekly batchPG Flexible Server, Memory Optimized tier, no HA, geo-restore for DR. Driver: cache-bound queries. Trade-off accepted: no HA — batch can rerun.
  4. Dev/test, 5 small DBsPG Flexible Server, Burstable B1ms, auto-stop after 7 days idle. Driver: pennies/month. Trade-off: cold-start delay on first connection.
  5. Cross-region read scale for global appPG Flexible Server primary in West Europe + 2 read replicas (East US, Southeast Asia). Driver: read latency at the edge. Trade-off: writes still cross-region; replica lag observable.

Flashcards

What is the recommended PostgreSQL deployment on Azure?
Click to reveal answer
Flexible Server. Single Server is deprecated.
1 / 6

Quiz

Q1/3
0 correct
Which PostgreSQL deployment option is recommended for new workloads on Azure?