ワンクリックで
polardb-daily-check
// Comprehensive daily health check for PolarDB for PostgreSQL databases, including LogIndex status, HTAP/MPP monitoring, shared storage performance, and high availability checks
// Comprehensive daily health check for PolarDB for PostgreSQL databases, including LogIndex status, HTAP/MPP monitoring, shared storage performance, and high availability checks
This skill is designed to perform comprehensive daily health checks on a PostgreSQL database. It leverages a suite of specialized SQL queries and analysis logic to provide insights into database availability, performance, activity, maintenance, storage, replication, and archiving status. The skill aims to identify potential issues such as blocking locks, long-running queries, transaction ID wraparound risks, bloat in tables and indexes, connection bottlenecks, and archiving failures.
Business intelligence analysis agent for PostgreSQL that discovers database metadata, generates SQL queries for revenue/customer/product metrics, and produces comprehensive analytical reports
| name | polardb-daily-check |
| description | Comprehensive daily health check for PolarDB for PostgreSQL databases, including LogIndex status, HTAP/MPP monitoring, shared storage performance, and high availability checks |
| license | MIT |
| compatibility | opencode |
This skill guides the agent in conducting a thorough daily health check of a PolarDB for PostgreSQL database instance. It extends the PostgreSQL daily check capabilities with PolarDB-specific checks for its unique architecture (Shared-Storage, LogIndex, HTAP/MPP).
The primary goal of this skill is to empower the agent to proactively monitor the health and performance of PolarDB for PostgreSQL, leveraging its unique features like storage-compute separation, LogIndex, and HTAP capabilities. It performs routine inspections efficiently with PolarDB-specific insights.
The agent performs checks across several key areas:
PolarDB uses LogIndex to maintain page replay history for read-only nodes, solving the "past page" problem. Key checks include:
PolarDB supports HTAP via distributed MPP execution engine:
polar_enable_px parameter controls MPP functionalityIn this architecture:
When activated, this skill executes a predefined sequence of checks:
Each item below represents a callable skill, returning structured JSON output.
get_polar_node_typepolar_node_type() function../run_polardb_check.sh get_polar_node_type{
"skill": "get_polar_node_type",
"status": "success",
"data": [
{
"node_type": "Primary",
"is_writable": true,
"polar_version": "2.0"
}
]
}
get_logindex_status./run_polardb_check.sh get_logindex_status{
"skill": "get_logindex_status",
"status": "success",
"data": [
{
"node_role": "ReadOnly",
"replay_lag_mb": 15,
"replay_lag_seconds": 2,
"pending_wal_count": 50
}
]
}
get_pfs_usagepfs_du_with_depth() and pfs_info()../run_polardb_check.sh get_pfs_usage{
"skill": "get_pfs_usage",
"status": "success",
"data": [
{
"total_size_gb": 500,
"used_size_gb": 350,
"used_percentage": 70,
"file_count": 15000
}
]
}
get_polar_process_statuspolar_stat_process() - PID, wait events, I/O stats, CPU, RSS../run_polardb_check.sh get_polar_process_status{
"skill": "get_polar_process_status",
"status": "success",
"data": [
{
"pid": 1234,
"state": "active",
"wait_event": "ClientRead",
"cpu_user": 5.2,
"cpu_system": 1.5,
"rss_mb": 2048,
"shared_storage_read_iops": 150,
"shared_storage_read_throughput_mbps": 50,
"shared_storage_read_latency_ms": 0.5
}
]
}
get_polar_activitypg_stat_activity and polar_stat_process()../run_polardb_check.sh get_polar_activity{
"skill": "get_polar_activity",
"status": "success",
"data": [
{
"pid": 1234,
"usename": "app_user",
"state": "active",
"query": "SELECT * FROM orders WHERE...",
"duration": "00:00:05",
"wait_event": "IO polarfs",
"shared_io": true
}
]
}
get_px_workers_status./run_polardb_check.sh get_px_workers_status{
"skill": "get_px_workers_status",
"status": "success",
"data": [
{
"polar_enable_px": true,
"polar_px_max_workers_number": 64,
"polar_px_dop_per_node": 8,
"active_px_queries": 3,
"total_px_workers": 24
}
]
}
get_px_query_stats./run_polardb_check.sh get_px_query_stats{
"skill": "get_px_query_stats",
"status": "success",
"data": [
{
"query_type": "PxScan",
"execution_count": 1500,
"avg_execution_time_ms": 45,
"total_rows_scanned": 5000000000
}
]
}
get_px_nodespolar_px_nodes../run_polardb_check.sh get_px_nodes{
"skill": "get_px_nodes",
"status": "success",
"data": [
{"node_id": 1, "node_name": "primary", "is_coordinator": true},
{"node_id": 2, "node_name": "readonly1", "is_worker": true},
{"node_id": 3, "node_name": "readonly2", "is_worker": true}
]
}
get_buffer_pool_affinity./run_polardb_check.sh get_buffer_pool_affinity{
"skill": "get_buffer_pool_affinity",
"status": "success",
"data": [
{
"buffer_hit_ratio": 99.5,
"local_buffer_usage": 80,
"shared_buffer_usage": 75
}
]
}
get_shared_storage_stats./run_polardb_check.sh get_shared_storage_stats{
"skill": "get_shared_storage_stats",
"status": "success",
"data": [
{
"read_iops": 5000,
"write_iops": 2000,
"read_throughput_mbps": 200,
"write_throughput_mbps": 100,
"read_latency_ms": 0.3,
"write_latency_ms": 0.5
}
]
}
get_polar_io_stats./run_polardb_check.sh get_polar_io_stats{
"skill": "get_polar_io_stats",
"status": "success",
"data": [
{
"polarfs_read_count": 1000000,
"polarfs_write_count": 500000,
"polarfs_read_bytes": "50 GB",
"polarfs_write_bytes": "25 GB",
"polarfs_iops": 8000,
"polarfs_throughput_mbps": 350
}
]
}
get_dirty_page_status./run_polardb_check.sh get_dirty_page_status{
"skill": "get_dirty_page_status",
"status": "success",
"data": [
{
"dirty_pages_count": 5000,
"dirty_bytes_mb": 200,
"flush_rate_pages_per_sec": 1000,
"oldest_modified_age": 120
}
]
}
get_primary_readonly_sync./run_polardb_check.sh get_primary_readonly_sync{
"skill": "get_primary_readonly_sync",
"status": "success",
"data": [
{
"primary_node": "node_primary",
"readonly_nodes": [
{
"node_name": "node_readonly1",
"sync_status": "streaming",
"lag_bytes": 5242880,
"lag_seconds": 1.5
}
]
}
]
}
get_online_promote_status./run_polardb_check.sh get_online_promote_status{
"skill": "get_online_promote_status",
"status": "success",
"data": [
{
"promote_ready": true,
"last_promote_time": "2024-01-15 10:30:00",
"promote_in_progress": false
}
]
}
get_recovery_progress./run_polardb_check.sh get_recovery_progress{
"skill": "get_recovery_progress",
"status": "success",
"data": [
{
"node_name": "node_readonly1",
"received_lsn": "0/ABCDEF00",
"replayed_lsn": "0/ABCDE800",
"replay_lag_bytes": 256,
"is_applying": true
}
]
}
The following skills are identical to the standard PostgreSQL daily check and work seamlessly with PolarDB.
| Skill | Description |
|---|---|
get_invalid_indexes | Check for corrupted indexes |
get_xid_wraparound_risk | Monitor transaction ID wraparound |
get_blocking_locks | Detect lock contention |
get_deadlock_detection | Check for past deadlocks |
get_critical_settings | Review critical parameters |
| Skill | Description |
|---|---|
get_long_running_queries | Find long-running queries |
get_idle_in_transaction_sessions | Find idle-in-transaction sessions |
get_long_running_transactions | Find long transactions |
get_connection_usage | Check connection pool usage |
get_lock_waiters | Detailed lock wait analysis |
get_wait_events | Current wait event analysis |
| Skill | Description |
|---|---|
get_cache_hit_rate | Cache efficiency metric |
get_rollback_rate | Transaction rollback ratio |
get_top_sql_by_time | Most expensive queries |
get_table_hotspots | Most active tables |
get_bgwriter_stats | Background writer metrics |
get_wal_statistics | WAL activity statistics |
| Skill | Description |
|---|---|
get_replication_slots | Replication slot status |
get_replication_status | Streaming replica lag |
get_wal_archiver_status | WAL archiving health |
| Skill | Description |
|---|---|
get_autovacuum_status | Active vacuum workers |
get_table_bloat | Table space bloat |
get_index_bloat | Index space bloat |
get_top_objects_by_size | Largest objects |
get_stale_statistics | Outdated table stats |
get_database_sizes | Database sizes |
| Skill | Description |
|---|---|
get_freeze_prediction | Predict freeze thresholds |
psql command-line tool (PostgreSQL client, version 10+)polar_monitor extension installed and availableConfigure database connection in assets/db_config.env:
export PGHOST="127.0.0.1"
export PGPORT="5432"
export PGUSER="digoal"
export PGPASSWORD="your_password"
export PGDATABASE="postgres"
Ensure the following extensions are available:
polar_monitor - Core PolarDB monitoring functionspg_stat_statements - SQL performance statistics (optional)pg_buffercache - Buffer pool analysis (optional)Verify PolarDB extensions are installed:
SELECT * FROM pg_extension WHERE extname LIKE 'polar%';
SELECT * FROM pg_extension WHERE extname = 'pg_stat_statements';
cd polardb-daily-check/scripts
# Run full health check (generates polar_daily_health_report.md)
python3 polardb_agent.py
# Or run via the bash wrapper
./run_polardb_check.sh full_check
./run_polardb_check.sh get_polar_node_type
./run_polardb_check.sh get_logindex_status
./run_polardb_check.sh get_pfs_usage
./run_polardb_check.sh get_px_workers_status
./run_polardb_check.sh get_shared_storage_stats
./run_polardb_check.sh get_long_running_queries
./run_polardb_check.sh get_table_bloat
./run_polardb_check.sh get_replication_status
./run_polardb_check.sh get_cache_hit_rate
The agent generates polar_daily_health_report.md with:
PolarDB-Specific Status
Overall Health Status
Detailed Findings
Actionable Recommendations
# PolarDB Daily Health Report
Generated: 2024-01-15 10:00:00
## PolarDB Status
- Node Type: Primary (Writable)
- LogIndex Lag: 5MB (2s) ✅ OK
- PFS Usage: 70% ✅ OK
- MPP Enabled: true ✅ OK
## Overall Status: ✅ HEALTHY
### Critical Issues
None
### Warnings
- 3 long-running queries detected
- Table 'orders' has 15% bloat
### Recommendations
1. Consider running VACUUM FULL on 'orders' table
2. Review slow queries in pg_stat_statements
polar_px_max_workers_number based on workloadALTER TABLE ... SET(px_workers=...) for large tables onlypolar_px_dop_per_node for parallel degreepolar_enable_px consistent across nodes| Skill | Category | Description |
|---|---|---|
get_polar_node_type | Core | Node type verification |
get_logindex_status | Core | LogIndex replay status |
get_pfs_usage | Core | PolarFS storage usage |
get_polar_process_status | Core | Detailed process metrics |
get_polar_activity | Core | Enhanced activity monitor |
| Skill | Category | Description |
|---|---|---|
get_px_workers_status | HTAP | MPP worker configuration |
get_px_query_stats | HTAP | Parallel query statistics |
get_px_nodes | HTAP | MPP cluster topology |
get_buffer_pool_affinity | HTAP | Buffer efficiency |
| Skill | Category | Description |
|---|---|---|
get_shared_storage_stats | I/O | Shared storage performance |
get_polar_io_stats | I/O | PolarFS detailed I/O |
get_dirty_page_status | I/O | Dirty page coordination |
| Skill | Category | Description |
|---|---|---|
get_primary_readonly_sync | HA | Primary-readonly sync |
get_online_promote_status | HA | Promotion readiness |
get_recovery_progress | HA | Recovery progress |
| Skill | Category | Description |
|---|---|---|
| All standard PostgreSQL checks | Various | 40+ compatibility skills |
This skill is designed for PolarDB for PostgreSQL and requires the polar_monitor extension. Standard PostgreSQL checks work on both PolarDB and regular PostgreSQL instances.
For more information about PolarDB architecture:
Base directory for this skill: file:///Users/digoal/.config/opencode/skills/polardb-daily-check Relative paths in this skill (e.g., scripts/, assets/) are relative to this base directory.