Cross-platform metric mapping for PostgreSQL
infoCross-Platform
Understanding how PostgreSQL metrics are named and exposed differently across monitoring platforms (CloudWatch, Cloud Monitoring, Azure Monitor, Datadog, Prometheus)
Prompt: “I'm migrating my PostgreSQL monitoring from Datadog to Prometheus. How do Datadog's postgresql.connections metric and AWS CloudWatch's DatabaseConnections metric map to the postgres_exporter metrics in Prometheus?”
With vs Without Schema
Same prompt, same model (claude-sonnet-4-5-20250929) — the only difference is whether Schema's knowledge graph was available.
Tokens
868vs1,109
Latency
18.1smsvs44.1sms
Turns
2vs8
Tool Calls
0vs3
Schema Calls
0vs2
Response
2,078 charsvs1,818 chars
Evaluation
Without Schema
A-
vs
With Schema
B+
Both responses provide correct metric mappings and actionable PromQL queries that would successfully guide the migration. The response without Schema is slightly more comprehensive, including concrete YAML alert examples and explicitly naming the pg_settings_superuser_reserved_connections metric, making it more immediately actionable for an SRE. The response with Schema mentions searching for information but doesn't demonstrate unique value from the knowledge graph access - the content is nearly identical but marginally less detailed, lacking the ready-to-use alert definitions that operators would find most valuable.
Without Schema
I can help you map these connection metrics between monitoring systems.
## Metric Mappings
### Datadog `postgresql.connections` → Prometheus
Datadog's `postgresql.connections` maps to **`pg_stat_database_numbackends`** in postgres_exporter:
```promql
# Total connections across all databases
sum(pg_stat_database_numbackends)
# Connections per database
pg_stat_database_numbackends{datname="your_database"}
```
If you were using Datadog's state-based connection metrics (active, idle, etc.), use **`pg_stat_activity_count`**:
```promql
# By connection state
pg_stat_activity_count{state="active"}
pg_stat_activity_count{state="idle"}
pg_stat_activity_count{state="idle in transaction"}
```
### AWS CloudWatch `DatabaseConnections` → Prometheus
CloudWatch's `DatabaseConnections` also maps to **`pg_stat_database_numbackends`**:
```promql
# Total connections (equivalent to CloudWatch metric)
sum(pg_stat_database_numbackends)
```
## Additional Useful Metrics
You'll likely also want these related metrics:
**Connection limits:**
```promql
# Maximum allowed connections
pg_settings_max_connections
# Connection utilization percentage
(sum(pg_stat_database_numbackends) / pg_settings_max_connections) * 100
```
**Reserved connections:**
```promql
pg_settings_superuser_reserved_connections
```
## Key Differences
1. **Granularity**: postgres_exporter provides per-database breakdown by default, while CloudWatch gives instance-level totals
2. **State information**: postgres_exporter offers detailed connection state data that neither Datadog nor CloudWatch provide natively
3. **Scrape vs Push**: Prometheus scrapes metrics (default 15s-1m intervals) vs Datadog/CloudWatch's push model
## Sample PromQL Alerts
```yaml
# High connection usage
- alert: HighConnectionUsage
expr: (sum(pg_stat_database_numbackends) / pg_settings_max_connections) > 0.8
# Too many idle connections
- alert: TooManyIdleConnections
expr: pg_stat_activity_count{state="idle"} > 50
```
Would you like help setting up specific dashboards or alerts for your Prometheus migration?
With Schema
3 tool calls2 Schema
I'll help you map these connection metrics across monitoring systems. Let me search for information about these metrics.
Based on my knowledge of these monitoring systems, here's how the connection metrics map:
## Metric Mapping
### **Datadog → Prometheus**
- **`postgresql.connections`** maps to **`pg_stat_database_numbackends`**
- Both measure the current number of connections per database
- In postgres_exporter, this comes from the `pg_stat_database` view
### **AWS CloudWatch → Prometheus**
- **`DatabaseConnections`** (RDS/Aurora) maps to **`sum(pg_stat_database_numbackends)`**
- CloudWatch aggregates across all databases
- Sum the Prometheus metric across all `datname` labels to get the total
## Key postgres_exporter Metrics for Connections
```promql
# Current connections per database (equivalent to Datadog's metric)
pg_stat_database_numbackends{datname="your_db"}
# Total connections across all databases (equivalent to CloudWatch)
sum(pg_stat_database_numbackends)
# Maximum allowed connections (useful for capacity planning)
pg_settings_max_connections
# Connection utilization percentage
(sum(pg_stat_database_numbackends) / pg_settings_max_connections) * 100
# Connections by state (idle, active, idle in transaction, etc.)
pg_stat_activity_count{state="active"}
```
## Important Differences
1. **Granularity**: Datadog and postgres_exporter provide per-database metrics, while CloudWatch gives instance-level totals
2. **State visibility**: postgres_exporter's `pg_stat_activity_count` provides more detail about connection states than CloudWatch
3. **Reserved connections**: Remember that PostgreSQL reserves `superuser_reserved_connections` (default 3), so effective max is slightly lower
Would you like help setting up Prometheus queries or alerts for connection monitoring?
Technologies
Related Insights
Relevant Metrics
Monitoring Interfaces
Redis Native Metrics
PostgreSQL Native