Managing Databases on Azure
The Azure DBA's core responsibilities across every service: provisioning, performance tuning, high availability and disaster recovery, security and compliance, and monitoring and cost control.
The Azure DBA's job
Whichever Azure database service you use, Microsoft runs the servers, patches the engine, and takes the backups. The DBA's job moves up a level: designing the right setup, keeping it fast, making sure it survives failures, locking it down, and keeping an eye on what it costs.
This lesson covers those five core responsibilities across Azure's managed databases: Azure SQL, Azure Database for PostgreSQL and MySQL, and Azure Cosmos DB. The tools differ by engine, but the job is the same.
Provisioning and architecture
Every new database starts with a set of design decisions, usually made with the application team:
- Service: which engine and service fits the application, as covered in Azure Database Services.
- Tier and size: for example, General Purpose or Business Critical for Azure SQL, Burstable or General Purpose for a Flexible Server, or provisioned or serverless throughput for Cosmos DB. Start modestly: scaling up later takes minutes.
- Where it lives: which subscription, resource group, and region, following the company's naming and tagging standards.
- Network: how applications will connect, ideally privately, as covered under security below.
Scaling is a single command, so sizing isn't a one-time decision:
# move an Azure SQL database to 4 vCores in the General Purpose tier
$ az sql db update --name salesdb --server kofi-sql-01 --resource-group rg-sales \
--edition GeneralPurpose --family Gen5 --capacity 4
# move a PostgreSQL Flexible Server to 4 vCores
$ az postgres flexible-server update --name kofi-pg-01 --resource-group rg-sales \
--sku-name Standard_D4ds_v5
Scaling usually ends with a brief disconnection, or a restart for a Flexible Server, so applications should be built to retry connections, and changes to production should be scheduled.
Performance tuning and optimization
Each engine keeps its own performance tools, and Azure adds some of its own on top:
| Service | Main performance tools |
|---|---|
| Azure SQL | Query Store, dynamic management views (DMVs), Extended Events, automatic tuning, database watcher |
| Azure Database for PostgreSQL | Query Store for PostgreSQL, pg_stat_statements, Query Performance Insight, intelligent tuning |
| Azure Database for MySQL | Slow query log, Performance Schema, Query Performance Insight |
| Azure Cosmos DB | Request unit (RU/s) use per operation, throttling metrics, and indexing policy |
- Query Store
- A built-in "flight recorder" that keeps the history of each query's performance, and in Azure SQL its execution plans. Azure SQL Database turns it on by default, and Azure Database for PostgreSQL has its own version. It's the first place to look when a query suddenly gets slower.
- Automatic and intelligent tuning
- Azure SQL Database can fix some problems on its own: by default it forces the last good plan when a plan change makes a query slower, and it can also create and drop indexes. Azure Database for PostgreSQL's intelligent tuning recommends indexes and settings.
- Database watcher
- An Azure service that collects detailed performance data from many Azure SQL databases into one place, with dashboards for spotting problems across a whole estate.
For example, finding the queries that take longest on average in Azure SQL and in PostgreSQL:
-- Azure SQL: from Query Store
SELECT TOP 5 qt.query_sql_text, rs.avg_duration
FROM sys.query_store_query_text qt
JOIN sys.query_store_query q ON q.query_text_id = qt.query_text_id
JOIN sys.query_store_plan p ON p.query_id = q.query_id
JOIN sys.query_store_runtime_stats rs ON rs.plan_id = p.plan_id
ORDER BY rs.avg_duration DESC;
-- PostgreSQL: from the pg_stat_statements extension
SELECT query, calls, mean_exec_time
FROM pg_stat_statements
ORDER BY mean_exec_time DESC
LIMIT 5;
High availability and disaster recovery
Every Azure database service keeps automated backups and can fail over within a region. The DBA decides how much further to go. Here's how it looks for Azure SQL:
- Zone-redundant deployment
- Keeps the database's copies, or its standby server, in different availability zones in the same region, so it keeps running if one zone fails. Azure SQL, Flexible Servers, and Cosmos DB all offer it.
- Failover groups
- An Azure SQL feature that replicates one or more databases, or a whole Managed Instance, to another region and fails them over together. Applications connect through the failover group's listener name, which always points to the current primary, so connection strings don't change after a failover.
The options for each service side by side:
| Service | Within a region | Across regions | Backups |
|---|---|---|---|
| Azure SQL | Built in, with optional zone redundancy | Active geo-replication or failover groups | Point-in-time restore for 1 to 35 days, plus long-term retention for up to 10 years |
| PostgreSQL and MySQL Flexible Server | Optional standby, in the same zone or another zone | Cross-region read replicas, promoted in a disaster | Point-in-time restore for up to 35 days, with geo-restore from geo-redundant backups |
| Azure Cosmos DB | Built in, with optional zone redundancy | Replicate to any number of regions, with automatic failover | Periodic, or continuous for point-in-time restore |
The DBA's job is to match these options to each database's RPO and RTO, from the Backup, Recovery, and High Availability lesson, and to test failovers and restores regularly.
Security and compliance
Under the shared responsibility model, Microsoft secures the platform, and the DBA secures the database. Azure database security works in layers, so getting past one doesn't give an attacker everything:
- Network: private endpoints and firewall rules
- Firewall rules decide which IP addresses can connect. Better still, a private endpoint, or for a Flexible Server, private access inside a virtual network, gives the database a private address, so it isn't reachable from the public internet at all.
- Identity: Microsoft Entra ID
- Every service supports signing in with company identities, with multifactor authentication and central control, instead of passwords stored in many places. Azure SQL can even switch off SQL logins entirely with Microsoft Entra-only authentication.
- Access: two kinds of permissions
- Azure role-based access control (RBAC) controls who can manage the database in Azure, such as scaling or deleting it. Database permissions, granted with
GRANTand roles as in the DCL lesson, control who can read and change the data. They're separate: an Azure administrator doesn't automatically see the data. - Data: encryption
- Every service encrypts data at rest and in transit by default, and most can use encryption keys the company manages itself. Azure SQL adds more: Transparent Data Encryption (TDE) encrypts the data files and backups; Always Encrypted encrypts the most sensitive columns inside the application, so even DBAs and Microsoft can't read them; and dynamic data masking hides parts of values, such as all but the last four digits of a card number.
- Monitoring: auditing and Defender
- Auditing and logs record who did what, for compliance with standards such as GDPR, HIPAA, and SOC 2. Microsoft Defender for Cloud includes database protection, Defender for SQL and for open-source relational databases, which alerts on suspicious activity such as SQL injection attempts or logins from unusual places.
Creating a database user for Kofi's Microsoft Entra account looks like this in Azure SQL and in PostgreSQL:
-- Azure SQL: add the user and give read access
CREATE USER [kofi@contoso.com] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER [kofi@contoso.com];
-- Azure Database for PostgreSQL, connected to the postgres database as an Entra admin
SELECT * FROM pgaadauth_create_principal('kofi@contoso.com', false, false);
Monitoring and cost control
Everything in the Cloud Cost Optimization lesson applies on Azure, using these tools for every service:
- Azure Monitor
- Collects metrics such as CPU, storage, connections, and request units, with alerts that notify the team, or trigger automation, when a threshold is crossed. Logs can be sent to a Log Analytics workspace for longer-term analysis.
- Microsoft Cost Management
- Shows what each subscription, resource group, and tagged resource costs, with budgets and alerts when spending heads over.
- Azure Advisor
- Recommends savings, such as databases that are consistently oversized.
The biggest savings, and which services they apply to:
| Saving | Applies to | How it works |
|---|---|---|
| Azure Hybrid Benefit | Azure SQL | Reuse SQL Server licenses the company already owns, with Software Assurance, instead of paying for them again in the hourly price. |
| Reservations | Most services | Commit to capacity for one or three years for steady production databases. |
| Serverless | Azure SQL Database, Cosmos DB | Pay for what's used, so idle development databases cost little. |
| Stop and start | PostgreSQL and MySQL Flexible Server | Stop development servers when nobody's using them, and pay only for storage. |
| Shared capacity | Azure SQL elastic pools, Cosmos DB autoscale | Let many databases share capacity, or scale throughput with demand, instead of paying for the peak all the time. |
| Right-sizing | Every service | Use Azure Monitor's history to scale down where capacity sits unused. |
In practice: the query that got slow overnight
On Monday morning, the order lookup in Azure SQL Database has gone from 50 milliseconds to 4 seconds. Nothing was deployed over the weekend. Kofi works through it with the tools in this lesson:
- Find it. Query Store's Regressed Queries report shows the lookup at the top, with two execution plans: the fast one used until Sunday, and a slow one since then.
- Explain it. Sunday's automatic statistics update led the optimizer to choose a full scan instead of an index seek.
- Fix it fast. Kofi forces the previous plan in Query Store, and the lookup is back to 50 milliseconds within minutes. (With automatic tuning's default setting, Azure SQL Database often does this by itself.)
- Fix it properly. Kofi then adds a covering index through the team's normal change process, so the optimizer picks a good plan on its own, and removes the forced plan.
The same skills as on-premises, plan regressions and indexing, with cloud tools that make each step faster.
Key takeaways
- The five core responsibilities, provisioning, performance, availability, security, and cost, are the same on every Azure database service; only the tools differ.
- Each engine keeps its own performance tools, such as Query Store for Azure SQL,
pg_stat_statementsfor PostgreSQL, and the slow query log for MySQL. Tune before you scale up. - Match zone redundancy, cross-region copies, and backups to each database's RPO and RTO, and test failovers and restores.
- Secure in layers: private networking, Microsoft Entra ID, separate Azure RBAC and database permissions, encryption, auditing, and Microsoft Defender for Cloud.
- Watch performance and spending with Azure Monitor and Microsoft Cost Management, and use the savings that fit each service.