Blog Post

Microsoft Blog for PostgreSQL
6 MIN READ

Is your PostgreSQL CPU-bound? Ask the new CPU limit metric

varun-dhawan's avatar
varun-dhawan
Icon for Microsoft rankMicrosoft
Dec 03, 2026

CPU at 90% of what? cpu_limit shows your server's vCore capacity, so you know when to scale and to what size.

By Varun Dhawan and Ajay Kumar Kushwaha, Microsoft PostgreSQL team

The problem: "the database is slow" and no clear answer

Your app slows down. Queries that used to take a second now take 20+. You open the portal and see CPU at 90%. But that raises more questions than it answers:

  • How many vCores does my server actually have right now?
  • Is this a short spike, or has the server been pinned for an hour?
  • Will scaling up fix it, and to what size?

Until now, CPU percent was the only CPU signal you had. It tells you how full the CPU is, not how big it is. To reason about capacity, you had to look up your compute size separately and do the math yourself.

What's new: the cpu_limit metric (preview)

cpu_limit reports the total number of vCores your server has, which is its CPU capacity. It is not the number of vCores still free. Put it next to CPU percent and you get the full picture:

vCores in use = (CPU percent Γ· 100) Γ— CPU limit

For example, a 4-vCore server (cpu_limit = 4) at 75% CPU is using 3 vCores, with 1 vCore of headroom.

When vCores in use sits at the CPU limit for a sustained period, your server is CPU-saturated. The fix is to reduce the load or add vCores.

The bigger win is history. cpu_limit records capacity over time, right next to utilization, so you can see when a server was scaled, what it was running on during an incident, and compare servers across a fleet.

Let's break a server on purpose

We ran a real experiment on a General-Purpose server running PostgreSQL 18. The workload: pgbench running CPU-heavy custom queries from 16 concurrent clients. To set it up, we scaled the server down from 16 to 2 vCores at 02:30. That's the first drop in the CPU limit line in the charts below.

Step

Setup

Result

πŸ”΄ 1. Under-sized

2 vCores (D2ds_v4)
16 clients, CPU-heavy queries

CPU pinned at ~92% for 40 min
Avg latency 26 s
Throughput 0.61 queries/s (max)

πŸ”” 2. Alert

2 vCores, load still running

Azure Monitor alert fired ~18 min into the load

⬆️ 3. Scale up

2 β†’ 4 vCores (D4ds_v4), online

Took ~11 min including restart
Alert auto-resolved

βœ… 4. Right-sized

4 vCores
Same queries at real demand (0.9 queries/s)

CPU ~48%
Avg latency 2.6 s (10Γ— faster)
Throughput 0.90 queries/s (target met)

How to read this: Step 1 ran unthrottled. Each client sent its next query as soon as the last one finished, so work piled up. Step 4 capped load at 0.9 queries/s, the app’s real demand, which 2 vCores couldn’t reach (max 0.61). The 10Γ— latency gain shows recovery from overload, not the effect of doubling vCores alone.

Step 1: Spot the saturation

The CPU percent chart shows a flat line at ~92% during the load. On its own that's a hint. Add cpu_limit and the picture firms up: the server has 2 vCores, and it is using ~1.8 of them, continuously, while latency sits at 26 s. Sustained saturation plus high latency makes a strong case for CPU as the bottleneck.

Figure 1: CPU percent

Plot vCores in use against cpu_limit and the problem is obvious. The blue area is pressed flat against the red limit line at 2 vCores. After the scale, the limit steps up to 4 and usage settles well below it.

Figure 2: CPU usage vs CPU limit in vCores

Which queries are driving the load? Once you know the server is saturated, find the heaviest queries. In the portal, use Query Performance Insight, which is backed by Query Store. Or query pg_stat_statements for the statements with the most total execution time. It’s a good starting point, though execution time includes waits, so it isn’t a pure CPU measure:

SELECT left(query, 80) AS query,
       calls,
       round(total_exec_time) AS total_ms,
       round(mean_exec_time)  AS mean_ms
FROM pg_stat_statements
ORDER BY total_exec_time DESC
LIMIT 5;

Step 2: Get alerted, don't stare at dashboards

We created a metric alert on CPU percent:

  • Condition: average cpu_percent > 90%
  • Window: 15 minutes, evaluated every 5 minutes
  • Severity: 2

A 15-minute window ignores short spikes (vacuum, a heavy report) and catches sustained saturation. When it fires, check cpu_limit to see how many vCores you have and how much headroom the next size would give you.

az monitor metrics alert create \
  --resource-group <rg> \
  --name pg-cpu-saturation \
  --scopes <server-resource-id> \
  --condition "avg cpu_percent > 90" \
  --window-size 15m \
  --evaluation-frequency 5m \
  --severity 2

Step 3: Scale with confidence

With 2 vCores pinned at ~92% and queries queuing, the server simply needed more CPU than it had. A practical rule of thumb: size so peak vCores in use stays around 70% of cpu_limit or less. Here that meant 4 vCores. Treat it as a starting point, not a guarantee: a saturated server hides demand that’s still queued, so confirm the new size against your latency and throughput goals.

az postgres flexible-server update \
  --resource-group <rg> \
  --name <server> \
  --sku-name Standard_D4ds_v4 \
  --tier GeneralPurpose

Heads up: Scaling compute restarts the server. Plan for a short connection interruption and make sure your app retries.

This post is about knowing when to scale. How to scale is a separate choice: near-zero downtime scaling, blue/green, or a standard scale operation. See the compute scaling docs for options.

Step 4: Confirm it's fixed

After the scale:

  • cpu_limit stepped from 2 to 4.
  • CPU percent settled around 48%, about 1.9 of 4 vCores, with room to grow. It didn't simply halve because the server is now doing more work: 0.90 queries/s instead of 0.61, a ~50% increase, for roughly the same vCores in use.
  • Query latency dropped from 26 s to 2.6 s. Why 10Γ—? On 2 vCores, queries spent most of their time waiting in line for CPU. With enough capacity for the demand, the queue drains and most of that wait disappears.
  • The alert resolved on its own.

You can see this on the right side of Figures 1 and 2: after 03:30, CPU limit steps up to 4 and vCores in use sit well below it.

How to turn it on

cpu_limit is in preview and is off by default. Enable it with one server parameter, which doesn't need a restart:

az postgres flexible-server parameter set \
  --resource-group <rg> \
  --server-name <server> \
  --name metrics.system_diagnostics \
  --value on

Allow up to 30 minutes for the first data point, so turn it on before you need it, not mid-incident. Then chart it in Azure Monitor metrics, workbooks, or Grafana.

Prefer Grafana? Azure Database for PostgreSQL includes built-in Grafana dashboards in the Azure portal, so you don't need to run a separate Grafana instance. Open Dashboards with Grafana from your server, edit the dashboard, and add a CPU limit panel next to CPU percent. For steps, see Edit a dashboard; for an overview, see Dashboards with Grafana – now in Azure portal for PostgreSQL.

Things to know

  • 30-minute granularity. cpu_limit is emitted every 30 minutes. Use a time grain of 30 minutes or coarser, and expect the newest interval to fill in after about 30 minutes. After a scale operation, the limit line steps at the 30-minute boundary, not the exact minute of the change.
  • Alert on CPU percent, interpret with CPU limit. CPU percent is the fast signal (1-minute grain), so use it for alerting. Use cpu_limit to understand capacity and size your next move.
  • Scaling isn't the only answer. Before you scale, check pg_stat_statements for the statements with the most execution time. A missing index or a runaway query can look exactly like an under-sized server.

Summary

CPU percent tells you the CPU is busy. cpu_limit tells you how much CPU you have. Together they turn "the database is slow" into a clear, data-backed decision: tune or scale, and by how much.

cpu_limit is in preview. Try it on your servers and tell us what you think in the comments.

Updated Dec 03, 2026
Version 3.0
No CommentsBe the first to comment