PolarDB Daily Check Agent
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).
Purpose
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.
Core Capabilities
The agent performs checks across several key areas:
- PolarDB Core Health: Node type verification, LogIndex status, PFS storage usage
- Availability & Health: Standard PostgreSQL health checks (invalid indexes, XID wraparound, blocking locks)
- Performance & Activity: Active sessions, long-running queries, cache efficiency, MPP parallel query performance
- HTAP & MPP: Parallel query statistics, worker status, coordinator coordination
- Storage & I/O: Shared storage performance, PolarFS usage, buffer pool status
- Replication & Consistency: Primary-readonly node sync status, LogIndex replay lag
PolarDB-Specific Checks
LogIndex Architecture
PolarDB uses LogIndex to maintain page replay history for read-only nodes, solving the "past page" problem. Key checks include:
- LogIndex replay status and latency
- WAL metadata consistency between primary and read-only nodes
- Lazy and Parallel replay efficiency
HTAP & MPP Architecture
PolarDB supports HTAP via distributed MPP execution engine:
- PxScan and Shuffle operators for parallel execution
- Coordinator-Worker coordination for skew elimination
- Serverless elastic scaling of compute nodes
polar_enable_px parameter controls MPP functionality
Storage-Compute Separation
In this architecture:
- Storage: Shared PolarFS, scales independently
- Compute: Multiple read-write and read-only nodes, stateless
- Benefits: No data replication during scaling, cost-effective read replicas
Workflow
When activated, this skill executes a predefined sequence of checks:
- First runs PolarDB-specific checks (node type, LogIndex, PFS)
- Then runs standard PostgreSQL compatibility checks
- Generates a comprehensive Markdown report with PolarDB-specific recommendations
Available Skills
Each item below represents a callable skill, returning structured JSON output.
1. PolarDB Core Health
Skill: get_polar_node_type
- Description: Checks the current PolarDB node type and role using
polar_node_type() function.
- Usage:
./run_polardb_check.sh get_polar_node_type
- Expected Output:
{
"skill": "get_polar_node_type",
"status": "success",
"data": [
{
"node_type": "Primary",
"is_writable": true,
"polar_version": "2.0"
}
]
}
- Analysis: Reports the node role (Primary/ReadOnly) and write capability.
Skill: get_logindex_status
- Description: Monitors LogIndex replay status and lag between primary and read-only nodes.
- Usage:
./run_polardb_check.sh get_logindex_status
- Expected Output:
{
"skill": "get_logindex_status",
"status": "success",
"data": [
{
"node_role": "ReadOnly",
"replay_lag_mb": 15,
"replay_lag_seconds": 2,
"pending_wal_count": 50
}
]
}
- Analysis: WARNING if replay lag >100MB or >10 seconds. CRITICAL if lag >1GB.
Skill: get_pfs_usage
- Description: Reports Polar File System (PFS) storage usage using
pfs_du_with_depth() and pfs_info().
- Usage:
./run_polardb_check.sh get_pfs_usage
- Expected Output:
{
"skill": "get_pfs_usage",
"status": "success",
"data": [
{
"total_size_gb": 500,
"used_size_gb": 350,
"used_percentage": 70,
"file_count": 15000
}
]
}
- Analysis: WARNING if usage >80%, CRITICAL if >90%.
Skill: get_polar_process_status
- Description: Detailed process information using
polar_stat_process() - PID, wait events, I/O stats, CPU, RSS.
- Usage:
./run_polardb_check.sh get_polar_process_status
- Expected Output:
{
"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
}
]
}
- Analysis: Reports detailed resource utilization per process.
Skill: get_polar_activity
- Description: Enhanced activity view combining
pg_stat_activity and polar_stat_process().
- Usage:
./run_polardb_check.sh get_polar_activity
- Expected Output:
{
"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
}
]
}
- Analysis: Enhanced monitoring with PolarDB-specific wait events.
2. HTAP & MPP Checks
Skill: get_px_workers_status
- Description: Checks MPP parallel query worker status and configuration.
- Usage:
./run_polardb_check.sh get_px_workers_status
- Expected Output:
{
"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
}
]
}
- Analysis: Reports MPP configuration and active parallel queries.
Skill: get_px_query_stats
- Description: Statistics on MPP parallel query execution and performance.
- Usage:
./run_polardb_check.sh get_px_query_stats
- Expected Output:
{
"skill": "get_px_query_stats",
"status": "success",
"data": [
{
"query_type": "PxScan",
"execution_count": 1500,
"avg_execution_time_ms": 45,
"total_rows_scanned": 5000000000
}
]
}
- Analysis: Monitors HTAP workload performance.
Skill: get_px_nodes
- Description: Lists nodes participating in MPP execution via
polar_px_nodes.
- Usage:
./run_polardb_check.sh get_px_nodes
- Expected Output:
{
"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}
]
}
- Analysis: Shows MPP cluster topology.
Skill: get_buffer_pool_affinity
- Description: Checks Buffer Pool affinity settings and effectiveness for MPP operations.
- Usage:
./run_polardb_check.sh get_buffer_pool_affinity
- Expected Output:
{
"skill": "get_buffer_pool_affinity",
"status": "success",
"data": [
{
"buffer_hit_ratio": 99.5,
"local_buffer_usage": 80,
"shared_buffer_usage": 75
}
]
}
- Analysis: Reports buffer efficiency for shared storage access.
3. Storage & I/O Performance
Skill: get_shared_storage_stats
- Description: Shared storage I/O performance metrics (IOPS, throughput, latency).
- Usage:
./run_polardb_check.sh get_shared_storage_stats
- Expected Output:
{
"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
}
]
}
- Analysis: WARNING if latency >5ms, CRITICAL if >10ms.
Skill: get_polar_io_stats
- Description: Detailed I/O statistics from PolarDB-specific monitoring.
- Usage:
./run_polardb_check.sh get_polar_io_stats
- Expected Output:
{
"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
}
]
}
- Analysis: Detailed PolarFS I/O patterns.
Skill: get_dirty_page_status
- Description: Dirty page flush status and coordination with read-only nodes.
- Usage:
./run_polardb_check.sh get_dirty_page_status
- Expected Output:
{
"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
}
]
}
- Analysis: Monitors primary node dirty page flushing coordination.
4. High Availability & Consistency
Skill: get_primary_readonly_sync
- Description: Synchronization status between primary and read-only nodes.
- Usage:
./run_polardb_check.sh get_primary_readonly_sync
- Expected Output:
{
"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
}
]
}
]
}
- Analysis: CRITICAL if any node not in streaming status.
Skill: get_online_promote_status
- Description: Checks readiness for online promotion capability.
- Usage:
./run_polardb_check.sh get_online_promote_status
- Expected Output:
{
"skill": "get_online_promote_status",
"status": "success",
"data": [
{
"promote_ready": true,
"last_promote_time": "2024-01-15 10:30:00",
"promote_in_progress": false
}
]
}
- Analysis: Reports online promotion readiness.
Skill: get_recovery_progress
- Description: Recovery progress for read-only nodes (if applicable).
- Usage:
./run_polardb_check.sh get_recovery_progress
- Expected Output:
{
"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
}
]
}
- Analysis: Monitors WAL replay progress.
5. PostgreSQL Compatibility Checks
The following skills are identical to the standard PostgreSQL daily check and work seamlessly with PolarDB.
Availability & Health
| 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 |
Session & Connection Monitoring
| 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 |
Performance & Activity
| 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 |
Replication & Archiving
| Skill |
Description |
get_replication_slots |
Replication slot status |
get_replication_status |
Streaming replica lag |
get_wal_archiver_status |
WAL archiving health |
Maintenance & Storage
| 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 |
Freeze & Wraparound Protection
| Skill |
Description |
get_freeze_prediction |
Predict freeze thresholds |
Environment Setup
Requirements
psql command-line tool (PostgreSQL client, version 10+)
- Python 3.6+ (uses only standard library, no additional packages)
polar_monitor extension installed and available
- Read access to PolarDB-specific functions
Configuration
Configure 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"
Required Extensions
Ensure the following extensions are available:
polar_monitor - Core PolarDB monitoring functions
pg_stat_statements - SQL performance statistics (optional)
pg_buffercache - Buffer pool analysis (optional)
Installation Check
Verify PolarDB extensions are installed:
SELECT * FROM pg_extension WHERE extname LIKE 'polar%';
SELECT * FROM pg_extension WHERE extname = 'pg_stat_statements';
Usage
Run Full Health Check
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 Individual PolarDB-Specific Checks
./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 Standard PostgreSQL Compatibility Checks
./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
Output
PolarDB Daily Health Report
The agent generates polar_daily_health_report.md with:
PolarDB-Specific Status
- Node type and role
- LogIndex replay lag
- PFS storage usage
- MPP/HTAP status
Overall Health Status
Detailed Findings
- PolarDB-specific issues
- Standard PostgreSQL issues
- Performance recommendations
Actionable Recommendations
- LogIndex optimization
- MPP tuning suggestions
- Storage capacity planning
- High availability readiness
Sample Report Structure
# 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
PolarDB-Specific Recommendations
LogIndex Optimization
- Monitor replay lag continuously
- If lag increases, check:
- Network bandwidth between compute and storage
- Storage I/O performance
- Read-only node workload
MPP Tuning
- Adjust
polar_px_max_workers_number based on workload
- Use
ALTER TABLE ... SET(px_workers=...) for large tables only
- Monitor
polar_px_dop_per_node for parallel degree
Storage Capacity
- Plan for 70% PFS usage threshold
- Consider storage tiering for cold data
- Monitor I/O latency for performance degradation
High Availability
- Test online promotion periodically
- Monitor sync lag between nodes
- Keep
polar_enable_px consistent across nodes
Skill Index
PolarDB Core Health
| 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 |
HTAP & MPP
| 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 |
Storage & I/O
| 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 |
High Availability
| Skill |
Category |
Description |
get_primary_readonly_sync |
HA |
Primary-readonly sync |
get_online_promote_status |
HA |
Promotion readiness |
get_recovery_progress |
HA |
Recovery progress |
PostgreSQL Compatibility
| Skill |
Category |
Description |
| All standard PostgreSQL checks |
Various |
40+ compatibility skills |
Notes
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:
- PolarDB Architecture Overview
- PolarDB HTAP Architecture
- PolarDB Operations Guide
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.
1---2name: polardb-daily-check3description: Comprehensive daily health check for PolarDB for PostgreSQL databases, including LogIndex status, HTAP/MPP monitoring, shared storage performance, and high availability checks4license: MIT5---6 7# PolarDB Daily Check Agent89This 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).1011## Purpose1213The 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.1415## Core Capabilities1617The agent performs checks across several key areas:1819* **PolarDB Core Health**: Node type verification, LogIndex status, PFS storage usage20* **Availability & Health**: Standard PostgreSQL health checks (invalid indexes, XID wraparound, blocking locks)21* **Performance & Activity**: Active sessions, long-running queries, cache efficiency, MPP parallel query performance22* **HTAP & MPP**: Parallel query statistics, worker status, coordinator coordination23* **Storage & I/O**: Shared storage performance, PolarFS usage, buffer pool status24* **Replication & Consistency**: Primary-readonly node sync status, LogIndex replay lag2526## PolarDB-Specific Checks2728### LogIndex Architecture2930PolarDB uses **LogIndex** to maintain page replay history for read-only nodes, solving the "past page" problem. Key checks include:3132- LogIndex replay status and latency33- WAL metadata consistency between primary and read-only nodes34- Lazy and Parallel replay efficiency3536### HTAP & MPP Architecture3738PolarDB supports HTAP via distributed MPP execution engine:3940- **PxScan** and **Shuffle** operators for parallel execution41- Coordinator-Worker coordination for skew elimination42- Serverless elastic scaling of compute nodes43- `polar_enable_px` parameter controls MPP functionality4445### Storage-Compute Separation4647In this architecture:4849- **Storage**: Shared PolarFS, scales independently50- **Compute**: Multiple read-write and read-only nodes, stateless51- **Benefits**: No data replication during scaling, cost-effective read replicas5253## Workflow5455When activated, this skill executes a predefined sequence of checks:561. First runs PolarDB-specific checks (node type, LogIndex, PFS)572. Then runs standard PostgreSQL compatibility checks583. Generates a comprehensive Markdown report with PolarDB-specific recommendations5960## Available Skills6162Each item below represents a callable skill, returning structured JSON output.6364---6566## 1. PolarDB Core Health6768### Skill: `get_polar_node_type`6970- **Description**: Checks the current PolarDB node type and role using `polar_node_type()` function.71- **Usage**: `./run_polardb_check.sh get_polar_node_type`72- **Expected Output**:73 ```json74 {75 "skill": "get_polar_node_type",76 "status": "success",77 "data": [78 {79 "node_type": "Primary",80 "is_writable": true,81 "polar_version": "2.0"82 }83 ]84 }85 ```86- **Analysis**: Reports the node role (Primary/ReadOnly) and write capability.8788### Skill: `get_logindex_status`8990- **Description**: Monitors LogIndex replay status and lag between primary and read-only nodes.91- **Usage**: `./run_polardb_check.sh get_logindex_status`92- **Expected Output**:93 ```json94 {95 "skill": "get_logindex_status",96 "status": "success",97 "data": [98 {99 "node_role": "ReadOnly",100 "replay_lag_mb": 15,101 "replay_lag_seconds": 2,102 "pending_wal_count": 50103 }104 ]105 }106 ```107- **Analysis**: WARNING if replay lag >100MB or >10 seconds. CRITICAL if lag >1GB.108109### Skill: `get_pfs_usage`110111- **Description**: Reports Polar File System (PFS) storage usage using `pfs_du_with_depth()` and `pfs_info()`.112- **Usage**: `./run_polardb_check.sh get_pfs_usage`113- **Expected Output**:114 ```json115 {116 "skill": "get_pfs_usage",117 "status": "success",118 "data": [119 {120 "total_size_gb": 500,121 "used_size_gb": 350,122 "used_percentage": 70,123 "file_count": 15000124 }125 ]126 }127 ```128- **Analysis**: WARNING if usage >80%, CRITICAL if >90%.129130### Skill: `get_polar_process_status`131132- **Description**: Detailed process information using `polar_stat_process()` - PID, wait events, I/O stats, CPU, RSS.133- **Usage**: `./run_polardb_check.sh get_polar_process_status`134- **Expected Output**:135 ```json136 {137 "skill": "get_polar_process_status",138 "status": "success",139 "data": [140 {141 "pid": 1234,142 "state": "active",143 "wait_event": "ClientRead",144 "cpu_user": 5.2,145 "cpu_system": 1.5,146 "rss_mb": 2048,147 "shared_storage_read_iops": 150,148 "shared_storage_read_throughput_mbps": 50,149 "shared_storage_read_latency_ms": 0.5150 }151 ]152 }153 ```154- **Analysis**: Reports detailed resource utilization per process.155156### Skill: `get_polar_activity`157158- **Description**: Enhanced activity view combining `pg_stat_activity` and `polar_stat_process()`.159- **Usage**: `./run_polardb_check.sh get_polar_activity`160- **Expected Output**:161 ```json162 {163 "skill": "get_polar_activity",164 "status": "success",165 "data": [166 {167 "pid": 1234,168 "usename": "app_user",169 "state": "active",170 "query": "SELECT * FROM orders WHERE...",171 "duration": "00:00:05",172 "wait_event": "IO polarfs",173 "shared_io": true174 }175 ]176 }177 ```178- **Analysis**: Enhanced monitoring with PolarDB-specific wait events.179180---181182## 2. HTAP & MPP Checks183184### Skill: `get_px_workers_status`185186- **Description**: Checks MPP parallel query worker status and configuration.187- **Usage**: `./run_polardb_check.sh get_px_workers_status`188- **Expected Output**:189 ```json190 {191 "skill": "get_px_workers_status",192 "status": "success",193 "data": [194 {195 "polar_enable_px": true,196 "polar_px_max_workers_number": 64,197 "polar_px_dop_per_node": 8,198 "active_px_queries": 3,199 "total_px_workers": 24200 }201 ]202 }203 ```204- **Analysis**: Reports MPP configuration and active parallel queries.205206### Skill: `get_px_query_stats`207208- **Description**: Statistics on MPP parallel query execution and performance.209- **Usage**: `./run_polardb_check.sh get_px_query_stats`210- **Expected Output**:211 ```json212 {213 "skill": "get_px_query_stats",214 "status": "success",215 "data": [216 {217 "query_type": "PxScan",218 "execution_count": 1500,219 "avg_execution_time_ms": 45,220 "total_rows_scanned": 5000000000221 }222 ]223 }224 ```225- **Analysis**: Monitors HTAP workload performance.226227### Skill: `get_px_nodes`228229- **Description**: Lists nodes participating in MPP execution via `polar_px_nodes`.230- **Usage**: `./run_polardb_check.sh get_px_nodes`231- **Expected Output**:232 ```json233 {234 "skill": "get_px_nodes",235 "status": "success",236 "data": [237 {"node_id": 1, "node_name": "primary", "is_coordinator": true},238 {"node_id": 2, "node_name": "readonly1", "is_worker": true},239 {"node_id": 3, "node_name": "readonly2", "is_worker": true}240 ]241 }242 ```243- **Analysis**: Shows MPP cluster topology.244245### Skill: `get_buffer_pool_affinity`246247- **Description**: Checks Buffer Pool affinity settings and effectiveness for MPP operations.248- **Usage**: `./run_polardb_check.sh get_buffer_pool_affinity`249- **Expected Output**:250 ```json251 {252 "skill": "get_buffer_pool_affinity",253 "status": "success",254 "data": [255 {256 "buffer_hit_ratio": 99.5,257 "local_buffer_usage": 80,258 "shared_buffer_usage": 75259 }260 ]261 }262 ```263- **Analysis**: Reports buffer efficiency for shared storage access.264265---266267## 3. Storage & I/O Performance268269### Skill: `get_shared_storage_stats`270271- **Description**: Shared storage I/O performance metrics (IOPS, throughput, latency).272- **Usage**: `./run_polardb_check.sh get_shared_storage_stats`273- **Expected Output**:274 ```json275 {276 "skill": "get_shared_storage_stats",277 "status": "success",278 "data": [279 {280 "read_iops": 5000,281 "write_iops": 2000,282 "read_throughput_mbps": 200,283 "write_throughput_mbps": 100,284 "read_latency_ms": 0.3,285 "write_latency_ms": 0.5286 }287 ]288 }289 ```290- **Analysis**: WARNING if latency >5ms, CRITICAL if >10ms.291292### Skill: `get_polar_io_stats`293294- **Description**: Detailed I/O statistics from PolarDB-specific monitoring.295- **Usage**: `./run_polardb_check.sh get_polar_io_stats`296- **Expected Output**:297 ```json298 {299 "skill": "get_polar_io_stats",300 "status": "success",301 "data": [302 {303 "polarfs_read_count": 1000000,304 "polarfs_write_count": 500000,305 "polarfs_read_bytes": "50 GB",306 "polarfs_write_bytes": "25 GB",307 "polarfs_iops": 8000,308 "polarfs_throughput_mbps": 350309 }310 ]311 }312 ```313- **Analysis**: Detailed PolarFS I/O patterns.314315### Skill: `get_dirty_page_status`316317- **Description**: Dirty page flush status and coordination with read-only nodes.318- **Usage**: `./run_polardb_check.sh get_dirty_page_status`319- **Expected Output**:320 ```json321 {322 "skill": "get_dirty_page_status",323 "status": "success",324 "data": [325 {326 "dirty_pages_count": 5000,327 "dirty_bytes_mb": 200,328 "flush_rate_pages_per_sec": 1000,329 "oldest_modified_age": 120330 }331 ]332 }333 ```334- **Analysis**: Monitors primary node dirty page flushing coordination.335336---337338## 4. High Availability & Consistency339340### Skill: `get_primary_readonly_sync`341342- **Description**: Synchronization status between primary and read-only nodes.343- **Usage**: `./run_polardb_check.sh get_primary_readonly_sync`344- **Expected Output**:345 ```json346 {347 "skill": "get_primary_readonly_sync",348 "status": "success",349 "data": [350 {351 "primary_node": "node_primary",352 "readonly_nodes": [353 {354 "node_name": "node_readonly1",355 "sync_status": "streaming",356 "lag_bytes": 5242880,357 "lag_seconds": 1.5358 }359 ]360 }361 ]362 }363 ```364- **Analysis**: CRITICAL if any node not in streaming status.365366### Skill: `get_online_promote_status`367368- **Description**: Checks readiness for online promotion capability.369- **Usage**: `./run_polardb_check.sh get_online_promote_status`370- **Expected Output**:371 ```json372 {373 "skill": "get_online_promote_status",374 "status": "success",375 "data": [376 {377 "promote_ready": true,378 "last_promote_time": "2024-01-15 10:30:00",379 "promote_in_progress": false380 }381 ]382 }383 ```384- **Analysis**: Reports online promotion readiness.385386### Skill: `get_recovery_progress`387388- **Description**: Recovery progress for read-only nodes (if applicable).389- **Usage**: `./run_polardb_check.sh get_recovery_progress`390- **Expected Output**:391 ```json392 {393 "skill": "get_recovery_progress",394 "status": "success",395 "data": [396 {397 "node_name": "node_readonly1",398 "received_lsn": "0/ABCDEF00",399 "replayed_lsn": "0/ABCDE800",400 "replay_lag_bytes": 256,401 "is_applying": true402 }403 ]404 }405 ```406- **Analysis**: Monitors WAL replay progress.407408---409410## 5. PostgreSQL Compatibility Checks411412The following skills are identical to the standard PostgreSQL daily check and work seamlessly with PolarDB.413414### Availability & Health415416| Skill | Description |417|-------|-------------|418| `get_invalid_indexes` | Check for corrupted indexes |419| `get_xid_wraparound_risk` | Monitor transaction ID wraparound |420| `get_blocking_locks` | Detect lock contention |421| `get_deadlock_detection` | Check for past deadlocks |422| `get_critical_settings` | Review critical parameters |423424### Session & Connection Monitoring425426| Skill | Description |427|-------|-------------|428| `get_long_running_queries` | Find long-running queries |429| `get_idle_in_transaction_sessions` | Find idle-in-transaction sessions |430| `get_long_running_transactions` | Find long transactions |431| `get_connection_usage` | Check connection pool usage |432| `get_lock_waiters` | Detailed lock wait analysis |433| `get_wait_events` | Current wait event analysis |434435### Performance & Activity436437| Skill | Description |438|-------|-------------|439| `get_cache_hit_rate` | Cache efficiency metric |440| `get_rollback_rate` | Transaction rollback ratio |441| `get_top_sql_by_time` | Most expensive queries |442| `get_table_hotspots` | Most active tables |443| `get_bgwriter_stats` | Background writer metrics |444| `get_wal_statistics` | WAL activity statistics |445446### Replication & Archiving447448| Skill | Description |449|-------|-------------|450| `get_replication_slots` | Replication slot status |451| `get_replication_status` | Streaming replica lag |452| `get_wal_archiver_status` | WAL archiving health |453454### Maintenance & Storage455456| Skill | Description |457|-------|-------------|458| `get_autovacuum_status` | Active vacuum workers |459| `get_table_bloat` | Table space bloat |460| `get_index_bloat` | Index space bloat |461| `get_top_objects_by_size` | Largest objects |462| `get_stale_statistics` | Outdated table stats |463| `get_database_sizes` | Database sizes |464465### Freeze & Wraparound Protection466467| Skill | Description |468|-------|-------------|469| `get_freeze_prediction` | Predict freeze thresholds |470471---472473## Environment Setup474475### Requirements476477- `psql` command-line tool (PostgreSQL client, version 10+)478- Python 3.6+ (uses only standard library, no additional packages)479- `polar_monitor` extension installed and available480- Read access to PolarDB-specific functions481482### Configuration483484Configure database connection in `assets/db_config.env`:485486```bash487export PGHOST="127.0.0.1"488export PGPORT="5432"489export PGUSER="digoal"490export PGPASSWORD="your_password"491export PGDATABASE="postgres"492```493494### Required Extensions495496Ensure the following extensions are available:497498- `polar_monitor` - Core PolarDB monitoring functions499- `pg_stat_statements` - SQL performance statistics (optional)500- `pg_buffercache` - Buffer pool analysis (optional)501502### Installation Check503504Verify PolarDB extensions are installed:505506```sql507SELECT * FROM pg_extension WHERE extname LIKE 'polar%';508SELECT * FROM pg_extension WHERE extname = 'pg_stat_statements';509```510511---512513## Usage514515### Run Full Health Check516517```bash518cd polardb-daily-check/scripts519520# Run full health check (generates polar_daily_health_report.md)521python3 polardb_agent.py522523# Or run via the bash wrapper524./run_polardb_check.sh full_check525```526527### Run Individual PolarDB-Specific Checks528529```bash530./run_polardb_check.sh get_polar_node_type531./run_polardb_check.sh get_logindex_status532./run_polardb_check.sh get_pfs_usage533./run_polardb_check.sh get_px_workers_status534./run_polardb_check.sh get_shared_storage_stats535```536537### Run Standard PostgreSQL Compatibility Checks538539```bash540./run_polardb_check.sh get_long_running_queries541./run_polardb_check.sh get_table_bloat542./run_polardb_check.sh get_replication_status543./run_polardb_check.sh get_cache_hit_rate544```545546---547548## Output549550### PolarDB Daily Health Report551552The agent generates `polar_daily_health_report.md` with:5535541. **PolarDB-Specific Status**555 - Node type and role556 - LogIndex replay lag557 - PFS storage usage558 - MPP/HTAP status5595602. **Overall Health Status**561 - OK / WARNING / CRITICAL5625633. **Detailed Findings**564 - PolarDB-specific issues565 - Standard PostgreSQL issues566 - Performance recommendations5675684. **Actionable Recommendations**569 - LogIndex optimization570 - MPP tuning suggestions571 - Storage capacity planning572 - High availability readiness573574### Sample Report Structure575576```markdown577# PolarDB Daily Health Report578Generated: 2024-01-15 10:00:00579580## PolarDB Status581- Node Type: Primary (Writable)582- LogIndex Lag: 5MB (2s) ✅ OK583- PFS Usage: 70% ✅ OK584- MPP Enabled: true ✅ OK585586## Overall Status: ✅ HEALTHY587588### Critical Issues589None590591### Warnings592- 3 long-running queries detected593- Table 'orders' has 15% bloat594595### Recommendations5961. Consider running VACUUM FULL on 'orders' table5972. Review slow queries in pg_stat_statements598```599600---601602## PolarDB-Specific Recommendations603604### LogIndex Optimization605606- Monitor replay lag continuously607- If lag increases, check:608 - Network bandwidth between compute and storage609 - Storage I/O performance610 - Read-only node workload611612### MPP Tuning613614- Adjust `polar_px_max_workers_number` based on workload615- Use `ALTER TABLE ... SET(px_workers=...)` for large tables only616- Monitor `polar_px_dop_per_node` for parallel degree617618### Storage Capacity619620- Plan for 70% PFS usage threshold621- Consider storage tiering for cold data622- Monitor I/O latency for performance degradation623624### High Availability625626- Test online promotion periodically627- Monitor sync lag between nodes628- Keep `polar_enable_px` consistent across nodes629630---631632## Skill Index633634### PolarDB Core Health635636| Skill | Category | Description |637|-------|----------|-------------|638| `get_polar_node_type` | Core | Node type verification |639| `get_logindex_status` | Core | LogIndex replay status |640| `get_pfs_usage` | Core | PolarFS storage usage |641| `get_polar_process_status` | Core | Detailed process metrics |642| `get_polar_activity` | Core | Enhanced activity monitor |643644### HTAP & MPP645646| Skill | Category | Description |647|-------|----------|-------------|648| `get_px_workers_status` | HTAP | MPP worker configuration |649| `get_px_query_stats` | HTAP | Parallel query statistics |650| `get_px_nodes` | HTAP | MPP cluster topology |651| `get_buffer_pool_affinity` | HTAP | Buffer efficiency |652653### Storage & I/O654655| Skill | Category | Description |656|-------|----------|-------------|657| `get_shared_storage_stats` | I/O | Shared storage performance |658| `get_polar_io_stats` | I/O | PolarFS detailed I/O |659| `get_dirty_page_status` | I/O | Dirty page coordination |660661### High Availability662663| Skill | Category | Description |664|-------|----------|-------------|665| `get_primary_readonly_sync` | HA | Primary-readonly sync |666| `get_online_promote_status` | HA | Promotion readiness |667| `get_recovery_progress` | HA | Recovery progress |668669### PostgreSQL Compatibility670671| Skill | Category | Description |672|-------|----------|-------------|673| *All standard PostgreSQL checks* | Various | 40+ compatibility skills |674675---676677## Notes678679This skill is designed for **PolarDB for PostgreSQL** and requires the `polar_monitor` extension. Standard PostgreSQL checks work on both PolarDB and regular PostgreSQL instances.680681For more information about PolarDB architecture:682- [PolarDB Architecture Overview](polar-doc/docs/zh/theory/arch-overview.md)683- [PolarDB HTAP Architecture](polar-doc/docs/zh/theory/arch-htap.md)684- [PolarDB Operations Guide](polar-doc/docs/zh/operation/)685686Base directory for this skill: file:///Users/digoal/.config/opencode/skills/polardb-daily-check687Relative paths in this skill (e.g., scripts/, assets/) are relative to this base directory.