Azure Database for PostgreSQL Monitoring

Deep monitoring for Azure Database for PostgreSQL — Flexible Server. Track query performance, index health, vacuum status, and high availability from a purpose-built PostgreSQL dashboard, not a generic Azure metrics pane.

Azure PostgreSQL: A Different Managed Experience

Azure Database for PostgreSQL Flexible Server is Microsoft's current-generation managed PostgreSQL offering. It provides zone-redundant high availability, configurable maintenance windows, and fine-grained control over server parameters — more operational flexibility than the retired Single Server tier, and more PostgreSQL-native behavior than competing cloud providers in some areas.

However, monitoring Azure PostgreSQL presents its own set of challenges. Azure Monitor provides infrastructure-level metrics (CPU, memory, storage, IOPS) but limited visibility into PostgreSQL internals. Azure's built-in Query Performance Insight feature is useful for finding top consumers, but it lacks the depth needed for serious optimization work — no index recommendations, no vacuum analysis, no schema change tracking.

MonPG fills these gaps by connecting directly to your Flexible Server instance and collecting the full range of PostgreSQL catalog statistics that Azure's native tools do not surface.

Setting Up MonPG on Azure

The MonPG collector runs inside your Azure environment — on a Virtual Machine, in an Azure Container Instance, or as a container in Azure Kubernetes Service. It connects to your Flexible Server over the private network using a standard PostgreSQL connection string.

VNet Integration

Most production Flexible Server deployments use VNet integration, meaning the database endpoint is only accessible from within the virtual network. The MonPG collector must run inside the same VNet (or a peered VNet) to reach the database. This is a security feature, not a limitation — it means your database metrics travel over private network paths, never over the public internet.

If your Flexible Server uses public access with firewall rules, you can run the collector anywhere that has network access to the endpoint, including outside Azure.

Enabling pg_stat_statements

Azure Flexible Server supports pg_stat_statements natively. You enable it by adding the extension to shared_preload_libraries in the server parameters and creating the extension in your database. A server restart is required for the parameter change, but this can be scheduled during your configured maintenance window to avoid unexpected downtime.

Once enabled, MonPG collects full query statistics — call counts, execution times, rows returned, block I/O — with 30-second granularity. This is dramatically more detailed than Azure's built-in Query Performance Insight, which samples queries at longer intervals and retains less historical data.

Azure Monitor vs MonPG: Complementary Tools

Azure Monitor is the right tool for infrastructure alerting — CPU usage, storage percentage, connection count limits. MonPG complements Azure Monitor by answering the questions that infrastructure metrics cannot:

  • Azure Monitor tells you CPU is at 90%. MonPG tells you which specific query is consuming that CPU, how long it has been running, and whether its performance regressed recently.
  • Azure Monitor tells you IOPS are spiking. MonPG tells you which tables are being scanned, which indexes are missing, and the estimated impact of adding them.
  • Azure Monitor tells you connections are near the limit. MonPG tells you how many are idle, how many are idle-in-transaction, which application is holding them, and how long they have been idle.
  • Azure Monitor tells you storage is growing. MonPG tells you which tables have the most dead tuples, whether autovacuum is keeping up, and whether bloat is contributing to storage consumption.

Most teams keep Azure Monitor alerts for infrastructure thresholds and use MonPG for daily performance analysis, query optimization, and capacity planning.

High Availability Monitoring

Azure Flexible Server supports zone-redundant high availability with automatic failover. In this configuration, a standby instance runs in a different availability zone and is promoted if the primary fails. MonPG monitors the HA status of your Flexible Server:

  • Replication status. MonPG tracks whether the standby is synchronized and the current replication lag.
  • Failover detection. When a failover occurs, MonPG detects the role change and records it as an event. You can see when failovers happened and correlate them with performance changes.
  • Read replica monitoring. Flexible Server supports read replicas for scaling read workloads. MonPG monitors each replica independently with per-replica query analysis and lag tracking.

Query Performance Insight vs MonPG

Azure's built-in Query Performance Insight (QPI) is available through the Azure Portal and provides a first-pass view of top queries by consumption. Here is how it compares to MonPG:

  • Granularity. QPI aggregates by 15-minute or longer windows. MonPG uses 30-second snapshots with delta computation.
  • Metrics depth. QPI shows execution count and duration. MonPG adds rows returned, block reads/writes, WAL usage, mean time per call, and cache hit ratio per query.
  • Recommendations. QPI identifies slow queries but does not recommend actions. MonPG provides index recommendations, unused index detection, and vacuum advisories.
  • Retention. QPI retention depends on your Log Analytics workspace configuration. MonPG retains query history for 14-90 days depending on your plan.
  • Regression detection.QPI does not track query regression. MonPG automatically detects when a query's performance degrades and alerts you with before/after metrics.

Log Analytics Integration

Azure Flexible Server can send PostgreSQL logs to a Log Analytics workspace, where you can query them with Kusto Query Language (KQL). This is useful for compliance and long-term retention but awkward for day-to-day troubleshooting — you need to know KQL syntax, and log entries are unstructured text that requires manual parsing.

MonPG's log insights pipeline collects PostgreSQL logs directly from the server, parses them into structured entries, and categorizes them automatically. Slow queries, lock waits, deadlocks, connection errors, and autovacuum events are identified and surfaced without manual KQL queries.

You can use both simultaneously: Log Analytics for compliance archival, and MonPG for real-time operational visibility.

Azure-Specific Metrics MonPG Tracks

Beyond the core PostgreSQL catalog statistics that MonPG collects on every platform, these Azure-specific concerns receive dedicated attention:

  • Server parameter changes. Flexible Server allows modifying many PostgreSQL parameters without restart. MonPG tracks parameter changes as schema events so you can correlate configuration changes with performance shifts.
  • Extension compatibility. Not all PostgreSQL extensions are available on Flexible Server. MonPG verifies which monitoring-relevant extensions are enabled and warns if any are missing.
  • Maintenance window awareness. Flexible Server supports custom maintenance windows. MonPG annotates metrics during maintenance periods so you do not confuse planned maintenance activity with genuine performance issues.
  • Compute tier utilization. MonPG helps you understand whether your current Flexible Server tier (Burstable, General Purpose, Memory Optimized) matches your workload, based on actual query and I/O patterns.

Related Resources

Monitor Your Azure PostgreSQL Today

Deploy the collector in your VNet, connect to your Flexible Server, and start seeing query-level metrics in minutes. Works alongside Azure Monitor without conflict.

Start trial