database-observability

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

$ 설치

git clone https://github.com/majiayu000/claude-skill-registry /tmp/claude-skill-registry && cp -r /tmp/claude-skill-registry/skills/data/database-observability ~/.claude/skills/claude-skill-registry

// tip: Run this command in your terminal to install the skill


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

AttributeExampleRequired
db.systempostgresql, mysqlYes
db.operationSELECT, INSERTYes
db.nameorders_dbYes
db.sql.tableusersRecommended
db.statementSELECT * FROM users WHERE id = ?Parameterized only!

Connection Pool Metrics (USE)

MetricTypeDescription
db.connections.activeGaugeIn use
db.connections.idleGaugeAvailable
db.connections.maxGaugePool limit
db.connections.wait_countCounterHad to wait
db.connections.wait_durationHistogramWait time

Issues to Detect

IssueDetectionFix
N+1 queries>10 identical queries per requestUse eager loading
Slow queriesDuration > p95 thresholdAdd indexes, optimize
Pool exhaustionwait_count increasingIncrease 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