{
  "uid": "briven-postgres-health",
  "title": "postgres · health",
  "tags": ["briven", "postgres"],
  "timezone": "browser",
  "schemaVersion": 39,
  "refresh": "30s",
  "time": { "from": "now-1h", "to": "now" },
  "panels": [
    {
      "id": 1,
      "title": "active connections",
      "type": "timeseries",
      "datasource": { "type": "prometheus", "uid": "Prometheus" },
      "gridPos": { "x": 0, "y": 0, "w": 12, "h": 8 },
      "targets": [
        {
          "expr": "pg_stat_activity_count",
          "legendFormat": "{{datname}}"
        }
      ]
    },
    {
      "id": 2,
      "title": "transactions / second",
      "type": "timeseries",
      "datasource": { "type": "prometheus", "uid": "Prometheus" },
      "gridPos": { "x": 12, "y": 0, "w": 12, "h": 8 },
      "targets": [
        {
          "expr": "rate(pg_stat_database_xact_commit[1m])",
          "legendFormat": "commits / {{datname}}"
        },
        {
          "expr": "rate(pg_stat_database_xact_rollback[1m])",
          "legendFormat": "rollbacks / {{datname}}"
        }
      ]
    },
    {
      "id": 3,
      "title": "deadlocks (last 1h)",
      "type": "stat",
      "datasource": { "type": "prometheus", "uid": "Prometheus" },
      "gridPos": { "x": 0, "y": 8, "w": 6, "h": 4 },
      "targets": [
        {
          "expr": "sum(increase(pg_stat_database_deadlocks[1h]))"
        }
      ]
    },
    {
      "id": 4,
      "title": "longest running query (s)",
      "type": "stat",
      "datasource": { "type": "prometheus", "uid": "Prometheus" },
      "gridPos": { "x": 6, "y": 8, "w": 6, "h": 4 },
      "targets": [
        {
          "expr": "max(pg_stat_activity_max_tx_duration)"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "s",
          "thresholds": {
            "steps": [
              { "value": 0, "color": "green" },
              { "value": 30, "color": "yellow" },
              { "value": 120, "color": "red" }
            ]
          }
        }
      }
    },
    {
      "id": 5,
      "title": "database size (per project schema)",
      "type": "timeseries",
      "datasource": { "type": "prometheus", "uid": "Prometheus" },
      "gridPos": { "x": 12, "y": 8, "w": 12, "h": 4 },
      "targets": [
        {
          "expr": "pg_database_size_bytes",
          "legendFormat": "{{datname}}"
        }
      ],
      "fieldConfig": {
        "defaults": { "unit": "bytes" }
      }
    }
  ]
}
