Skip to content
Back to skills

Database Observability

ASecurity

Instrument database queries, connection pools, and detect N+1 queries

  • 666 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added February 8, 2026
databasesgosqldatabase

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add majiayu000/claude-skill-registry --skill database-observability --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Database Observability?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Database Observability
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-database-observability/badge)](https://www.skillsdirectory.com/skills/majiayu000-database-observability)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: database-observability
description: "Instrument database queries, connection pools, and detect N+1 queries"
triggers:
  - "instrument database"
  - "trace queries"
  - "database metrics"
  - "connection pool monitoring"
  - "slow query detection"
priority: 2
---

# Database Observability

Database is often the bottleneck. Track queries, pools, and patterns.

## Query Span Attributes

| Attribute | Example | Required |
|-----------|---------|----------|
| `db.system` | postgresql, mysql | Yes |
| `db.operation` | SELECT, INSERT | Yes |
| `db.name` | orders_db | Yes |
| `db.sql.table` | users | Recommended |
| `db.statement` | SELECT * FROM users WHERE id = ? | **Parameterized only!** |

## Connection Pool Metrics (USE)

| Metric | Type | Description |
|--------|------|-------------|
| `db.connections.active` | Gauge | In use |
| `db.connections.idle` | Gauge | Available |
| `db.connections.max` | Gauge | Pool limit |
| `db.connections.wait_count` | Counter | Had to wait |
| `db.connections.wait_duration` | Histogram | Wait time |

## Issues to Detect

| Issue | Detection | Fix |
|-------|-----------|-----|
| **N+1 queries** | >10 identical queries per request | Use eager loading |
| **Slow queries** | Duration > p95 threshold | Add indexes, optimize |
| **Pool exhaustion** | wait_count increasing | Increase pool, fix leaks |

## Query Wrapper Pattern

```
Before: Start span (db.system, db.operation, db.sql.table), start timer
After:  Record duration, set db.rows_affected, record errors, end span
```

## Pool Monitor Pattern

```
Every 10s: Record active, idle, wait_count, wait_duration from pool stats
```

## Anti-Patterns

- **Full SQL with values** → PII risk, use parameterized only
- **No pool metrics** → Can't detect saturation
- **Missing slow query alerts** → Problems go unnoticed

## References

- `references/methodology/use-methodology.md`
- `references/platforms/{platform}/database.md`

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.