スキル一覧に戻る
AmnadTaowsoam

database-health-monitoring

by AmnadTaowsoam

0🍴 0📅 2026年1月24日
GitHubで見るManusで実行

SKILL.md


name: Database Health Monitoring description: Continuous monitoring and diagnostics for ensuring high availability, performance, and stability of database systems.

Database Health Monitoring

Overview

Database Health Monitoring is the practice of tracking internal and infrastructure metrics to identify performance bottlenecks, hardware failures, or configuration issues before they cause service outages.

Core Principle: "The database is usually the performance bottleneck. Measure everything from disk latency to query locks."


1. Core Health Metrics (Gold Standard)

Regardless of the database engine, these four areas must be monitored:

CategoryMetricCritical Threshold
UtilizationCPU Usage> 80% sustained.
MemoryFreeable Memory< 5% of total RAM.
SaturationDisk I/O Queue Depth> 5-10 operations.
ErrorsConnection FailuresAny > 0 per minute.

2. Engine-Specific Metrics

PostgreSQL

  • Transaction Lag: Time between primary and replica syncing.
  • Autovacuum Progress: Ensuring dead tuples (deleted rows) are cleaned up.
  • Transaction Wrapper Overrun: High-risk scenario where the DB stops to prevent data corruption.

Redis

  • Memory Fragmentation Ratio: High fragmentation (> 1.5) means Redis is wasting RAM.
  • Evicted Keys: Increasing evictions mean the cache is too small.

MongoDB

  • Page Faults: High faults mean the "Working Set" doesn't fit in RAM.
  • Write Ticket Availability: Bottlenecks in the WiredTiger storage engine.

3. Performance Tuning: The "Explain" Workflow

A healthy database is nothing without efficient queries.

  1. Detect: Use "Slow Query Logs" to find queries taking > 500ms.
  2. Analyze: Run EXPLAIN ANALYZE on the query.
EXPLAIN ANALYZE SELECT * FROM orders WHERE customer_id = '123';
  1. Optimize:
    • Missing Index: Create an index.
    • Full Table Scan: Add filters or rewrite query.
    • Large Join: Denormalize or use a read replica.

4. Connection Pool Monitoring

Connection pool exhaustion is a common cause of SEV0 incidents.

  • Active Connections: How many threads are currently running a query?
  • Idle Connections: How many are "waiting"?
  • Wait Time: How long does an application wait to get a connection?

Strategy: If Wait Time > 10ms, you need to either increase the max connections or fix leaking connections in your code.


5. Monitoring Tools

ToolFocusBest For
Datadog DB MonitoringFull StackDeep "Explain" plan visibility and DPM (Database Performance Monitoring).
Grafana + PrometheusOpen SourceCustom dashboards via postgres_exporter.
Percona PMMSQL ExpertDetailed InnoDB/Postgres internal metrics.
AWS CloudWatchInfrastructureEBS IOPS, RAM, and Burst Credits.

6. Critical Alerting Thresholds

Set up your PagerDuty/Slack alerts based on these baselines:

  • Disk Space: Alert at 85% full. (Critical: DBs usually crash or go read-only at 95%).
  • Replication Lag: Alert if > 60 seconds. (Critical: Replica data is "stale").
  • Slow Queries: Alert if slow_query_count > 10 per minute.
  • CPU Saturation: Alert if Load Average > Number of Cores.

7. Diagnostic SQL Script (PostgreSQL)

Run this to find currently "blocking" queries (locks):

SELECT 
    blocked_locks.pid AS blocked_pid,
    blocking_locks.pid AS blocking_pid,
    blocked_activity.query AS blocked_statement,
    blocking_activity.query AS blocking_statement
FROM pg_catalog.pg_locks AS blocked_locks
JOIN pg_catalog.pg_stat_activity AS blocked_activity ON blocked_activity.pid = blocked_locks.pid
JOIN pg_catalog.pg_locks AS blocking_locks ON blocking_locks.locktype = blocked_locks.locktype
JOIN pg_catalog.pg_stat_activity AS blocking_activity ON blocking_activity.pid = blocking_locks.pid
WHERE NOT blocked_locks.granted;

8. Real-World Scenario: The "Zombie" Transaction

  • Scenario: A dashboard suddenly stopped updating. CPU and RAM were 10%.
  • Discovery: Monitoring showed a Row Lock on the main metrics table.
  • Investigation: An internal script started a transaction to update a row but crashed before sending COMMIT.
  • Remediation: Used the "Blocking Query" script to find the PID (Process ID) of the zombie transaction and ran SELECT pg_terminate_backend(pid).
  • Outcome: Lock released, dashboard resumed, 15-minute outage resolved.

9. Database Health Checklist

  • Backups: Have we verified a successful backup restore in the last 30 days?
  • IOPS: Are we consistently exceeding 80% of our provisioned IOPS?
  • Indexes: Have we run an "Unused Index" report to remove performance overhead?
  • Alerts: Do we have an alert for "Max Connections" reaching 90%?
  • Security: Are we monitoring for "Failed Login" spikes (Brute force)?
  • Patches: Is the DB engine running a supported, minor version update?

  • 42-cost-engineering/infra-sizing
  • 43-data-reliability/data-quality-monitoring
  • 41-incident-management/oncall-playbooks

スコア

総合スコア

60/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です