Agent skill

Mysql Replication Lag Resolver

by openocta in openocta/openocta_skills

Replication lag root cause analysis with automated resolution workflow.

MITAuto-check passedDatabases

Install Mysql Replication Lag Resolver

skills CLI
$ npx skills add openocta/openocta_skills --skill mysql-replication-lag-resolver -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install openocta/openocta_skills mysql-replication-lag-resolver --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/openocta/openocta_skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/mysql-replication-lag-resolver .claude/skills/mysql-replication-lag-resolver && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
mysql-replication-lag-resolver
GitHub stars
166
Token cost
~2.6k tokens
SKILL.md length
695 words
Files
3
Skills in repo
8
Repo updated
First seen
Licence
MIT

At a glance

Replication lag root cause analysis with automated resolution workflow.

  • Works in 6 steps: Assess Replication Health → Identify Root Cause on Master → Classify Candidates → …
  • Tasks that involve Database administration
  • SKILL.md covers Overview, When to Use, Required MCP Server and ⚠️ CRITICAL: Safety Rules, plus 5 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Mysql Replication Lag Resolver is an agent skill from openocta/openocta_skills. Replication lag root cause analysis with automated resolution workflow. Detects lag, identifies blocking queries on the master, presents KILL candidates with safety classification, and executes KILL only after double user confirmation. Reduces recovery from 20 minutes to 2 minutes.

Its SKILL.md is about 2.6k tokens, which your agent loads only when the skill is triggered. The skill folder holds 2 other files (for example `README.md` and `mate.json`).

It sits in Databases, covering Database administration, GraphQL and Root cause analysis. It works with MySQL. The repository describes itself as: 本仓库用于汇集第三方贡献的 OpenOcta 技能(Skill)资源,便于分享、版本管理与分发。 The licence is MIT.

When your agent uses it

  • Tasks that involve Database administration
  • Tasks that involve GraphQL
  • Tasks that involve Root cause analysis

Example prompts

  • “/mysql-replication-lag-resolver”

Requirements

  • Pre-approved tools (allowed-tools): db_query, db_get_status, db_get_processlist, db_kill_query

Workflow steps

6 steps, taken from the step headings in SKILL.md.

  1. Assess Replication Health
  2. Identify Root Cause on Master
  3. Classify Candidates
  4. Present to User
  5. Execute KILL (After Confirmation)
  6. Monitor Recovery

What it can do on your machine

Read from SKILL.md and the folder at commit 6ac4479. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • db_query
    • db_get_status
    • db_get_processlist
    • db_kill_query

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are sql).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Mysql Replication Lag Resolver loads about 2.6k tokens when it runs. Until then it costs about 78 tokens; SKILL.md has 695 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~78
When it runs · the whole SKILL.md, loaded when a task matches
~2.6k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from openocta/openocta_skills at commit 6ac4479, republished under its MIT licence (© openocta). 695 words, ~2,588 tokens.

Download SKILL.mdSave it as .claude/skills/mysql-replication-lag-resolver/SKILL.md (or your agent's skills folder). This skill also uses 2 other files; get the full folder from GitHub.
name
mysql-replication-lag-resolver
description
Replication lag root cause analysis with automated resolution workflow. Detects lag, identifies blocking queries on the master, presents KILL candidates with safety classification, and executes KILL only after double user confirmation. Reduces recovery from 20 minutes to 2 minutes.
allowed-tools
db_query, db_get_status, db_get_processlist, db_kill_query
version
1.0.0

MySQL Replication Lag Resolver (Auto-Diagnose + Fix)

Overview

Replication lag is one of the most critical database incidents — it means read replicas are falling behind the master, serving stale data to applications. Traditional resolution requires DBA to: receive alert → open laptop → connect VPN → login to jumpbox → check slave status → find blocking queries on master → decide what to kill → execute KILL → monitor recovery. 20+ minutes at 2 AM.

This skill automates the entire diagnosis and presents a one-click resolution:

  1. Detect — Check Seconds_Behind_Master and replication health
  2. Root Cause — Find long-running queries on master blocking binlog sync
  3. Classify — Mark each query as safe/caution/dangerous to kill
  4. Present — Show candidates with impact analysis
  5. Resolve — Execute KILL with double user confirmation
  6. Verify — Monitor lag recovery in real-time

Real-world result: From 20 minutes to 2 minutes — 10x improvement. DBA only needs to say "confirm" on their phone.

When to Use

Apply this skill when:

  • Replication lag alert fires (Seconds_Behind_Master > threshold)
  • Application reports stale reads from replicas
  • Scheduled monitoring detects lag trend
  • After bulk operations (data migration, batch updates) that may cause lag
  • Proactive check during peak hours

Required MCP Server

ToolPurposeExample
db_queryCheck replication statusdb_query("SHOW SLAVE STATUS")
db_get_statusGet replication countersdb_get_status("Seconds_Behind_Master")
db_get_processlistFind blocking queriesdb_get_processlist()
db_kill_queryTerminate blocking queriesdb_kill_query(thread_id=123)
Required MySQL Privileges
  • REPLICATION CLIENT — View replication status
  • PROCESS — View all threads on master
  • SUPER or CONNECTION_ADMIN — KILL queries (on master only)

⚠️ CRITICAL: Safety Rules

NEVER Kill
  • Replication threads (system user on slaves)
  • DDL operations (ALTER, CREATE, DROP) — killing DDL on master can corrupt data dictionary
  • The diagnostic session itself
  • Any thread running < 60 seconds (may be legitimate)
KILL with Caution
TypeRiskGuidance
UPDATE/DELETEPartial rollback, breaks idempotent operationsKill only if > 300s AND lag is critical
INSERT...SELECTMay leave partial dataVerify target table before killing
Large SELECTSafe but wastes workPrefer killing SELECTs first
Mandatory Approval Protocol

This skill enforces double-confirmation for ALL KILL operations:

  1. Phase 1: Present findings + candidates
  2. Phase 2: User selects targets ("KILL 123, 124")
  3. Phase 3: AI reads back + user types "CONFIRM KILL"
  4. Phase 4: Execute KILL
  5. Phase 5: Monitor recovery

Diagnostic Workflow

Step 1: Assess Replication Health
sql
-- Master status
SHOW MASTER STATUS;

-- Slave status (run on replica)
SHOW SLAVE STATUS\G

-- Key fields from SHOW SLAVE STATUS:
--   Seconds_Behind_Master: {lag_seconds}
--   Slave_IO_Running: Yes/No
--   Slave_SQL_Running: Yes/No
--   Last_Error: {error_message}
--   Relay_Master_Log_File: {master_log}
--   Exec_Master_Log_Pos: {executed_pos}
--   Read_Master_Log_Pos: {read_pos}

Classify lag severity:

Seconds_Behind_MasterSeverityAction
0-30✅ NormalNo action needed
30-120🟡 WarningMonitor, check trend
120-600🔴 HighDiagnose root cause
> 600🔴 CriticalImmediate intervention
Show full SKILL.md (306 more words)Show less
Step 2: Identify Root Cause on Master
sql
-- Find long-running queries on master that may block binlog sync
SELECT
  ID, USER, HOST, DB, COMMAND,
  TIME AS duration_sec,
  STATE,
  LEFT(INFO, 300) AS sql_fragment
FROM information_schema.PROCESSLIST
WHERE COMMAND != 'Sleep'
  AND TIME > 60
  AND USER != 'system user'
ORDER BY TIME DESC;

-- Check master binlog position vs what slaves have read
SHOW MASTER STATUS;
-- Compare with Exec_Master_Log_Pos from each slave

Root cause patterns:

PatternCauseFix
Long SELECT on masterBinlog events queued behind the SELECTKill the SELECT
Large UPDATE/DELETESingle big transaction blocks binlogKill if > 300s
Binlog Dump idleNetwork issue between master/slaveCheck network, not kill
Slave_SQL stoppedDuplicate key / constraint errorFix error, START SLAVE
Step 3: Classify Candidates

For each long-running query on master, classify:

IF SQL starts with ALTER/CREATE/DROP/TRUNCATE/RENAME:
  → Type: DDL, Kill: NOT RECOMMENDED (explain risk to user)
ELSE IF SQL starts with SELECT:
  → Type: SELECT, Kill: SAFE (kill first)
ELSE IF SQL starts with UPDATE/DELETE and duration > 300:
  → Type: DML, Kill: CAUTION (present risk)
ELSE IF Command = 'Binlog Dump':
  → Type: REPLICATION, Kill: NEVER
ELSE:
  → Type: OTHER, Kill: REVIEW
Step 4: Present to User

Show candidates using the template below. Wait for user response.

Step 5: Execute KILL (After Confirmation)
sql
-- Kill confirmed threads
KILL {thread_id};

-- If KILL fails (thread already gone), report it
-- Alternative: KILL QUERY {thread_id} (kills query, keeps connection)
Step 6: Monitor Recovery

After killing, check lag every 10-30 seconds:

sql
-- Recheck slave status
SHOW SLAVE STATUS\G

-- Expected recovery pattern:
-- Seconds_Behind_Master: 623 → 412 → 89 → 0

Report recovery timeline to user.

Output Templates

Initial Diagnosis
🔄 Replication Lag Alert
═══════════════════════
📊 Current Status
  Master: {host}:{port} (Binlog: {file}, Pos: {pos})
  Slave:  {host}:{port}
  Lag: {seconds}s 🔴 CRITICAL
  IO Thread: {io_status}
  SQL Thread: {sql_status}

🔍 Root Cause Analysis
  Cause: {count} long-running queries on master blocking binlog sync
  Impact: Slave is {seconds}s behind, serving stale data to {app_count} applications

📋 Blocking Queries (candidates for KILL)
  | Thread | User | Duration | Type | SQL | Kill Safety |
  |--------|------|----------|------|-----|-------------|
  | 23451  | app1 | 892s     | SELECT | SELECT ... FROM order_detail | ✅ Safe |
  | 23487  | app2 | 567s     | SELECT | SELECT ... FROM user_session | ✅ Safe |
  | 23502  | app3 | 423s     | SELECT | SELECT ... FROM payment_record | ✅ Safe |

  ℹ️ Skipped: 2 Binlog Dump threads (replication, NEVER kill)

⚠️ Action Required (Step 1 of 2):
  Reply "KILL {thread_ids}" to select targets,
  "KILL ALL" for all candidates,
  or "SKIP" to cancel.
  ⚠️ A final confirmation will be required before execution.
After User Selects (Double Confirmation)
⚠️ DOUBLE CONFIRMATION REQUIRED (Step 2 of 2)
══════════════════════════════════════════════
You are about to KILL {count} queries on MASTER:

  | Thread | User | Duration | Type | SQL |
  |--------|------|----------|------|-----|
  | 23451  | app1 | 892s     | SELECT | ... |
  | 23487  | app2 | 567s     | SELECT | ... |
  | 23502  | app3 | 423s     | SELECT | ... |

  ❗️ Please type EXACTLY "CONFIRM KILL" to proceed.
     Any other response cancels this operation.
Recovery Report
✅ KILL Execution Complete
═════════════════════════
  Thread 23451 (892s, SELECT): ✅ Killed
  Thread 23487 (567s, SELECT): ✅ Killed
  Thread 23502 (423s, SELECT): ✅ Killed

📈 Recovery Timeline
  0s:   Lag = 623s (KILL executed)
  30s:  Lag = 412s ↓
  60s:  Lag = 89s ↓
  90s:  Lag = 0s ✅ Replication normalized

💡 Root Cause Summary:
  3 concurrent full-table-scan queries on master blocked binlog sync.
  Recommended: Add indexes on order_detail(status, create_time) and
  user_session(last_active) to prevent recurrence.

Example Usage

User: "Replication lag alert on db-slave-01"

AI (Phase 1):

🔄 Replication Lag Alert
═══════════════════════
  Slave: db-slave-01:3306
  Lag: 623s 🔴 CRITICAL
  Root Cause: 3 long-running SELECT queries on master blocking binlog sync

  KILL candidates:
    23451 · app1 · 892s · SELECT * FROM order_detail WHERE ...
    23487 · app2 · 567s · SELECT * FROM user_session WHERE ...
    23502 · app3 · 423s · SELECT * FROM payment_record WHERE ...

  Reply "KILL ALL" or specify thread IDs.

User: "KILL ALL"

AI (Phase 3 — Double check):

⚠️ CONFIRM: Kill all 3 queries on master?
Type "CONFIRM KILL" to proceed.

User: "CONFIRM KILL"

AI (Phase 4+5):

✅ 3 queries killed. Lag recovering: 623 → 412 → 89 → 0. Normalized.

Best Practices

Preventing Replication Lag
PreventionHow
Set long_query_time lowSET GLOBAL long_query_time = 1
Monitor lag proactivelyCheck every 30s, alert at > 60s
Use row-based replicationRBR is more efficient for most workloads
Batch operationsSplit large UPDATEs into 1000-row batches
Parallel replicationSET GLOBAL slave_parallel_workers = 4 (MySQL 5.7+)
After Resolving Lag
  1. Check data consistency — Compare row counts on master vs slave for critical tables
  2. Root cause remediation — Add missing indexes to prevent recurrence
  3. Update monitoring — Lower alert threshold if this was a recurring issue
  4. Notify stakeholders — Applications may have cached stale data

Quick Reference

ActionCommand
Check slave statusSHOW SLAVE STATUS\G
Check master statusSHOW MASTER STATUS
Start slaveSTART SLAVE
Stop slaveSTOP SLAVE
Skip one replication errorSET GLOBAL sql_slave_skip_counter = 1; START SLAVE
Show long queriesSELECT * FROM information_schema.PROCESSLIST WHERE TIME > 60
Kill a threadKILL {thread_id}
Kill query onlyKILL QUERY {thread_id}

Use this skill when replication lag fires — diagnose, present options, resolve with one confirmation.

© openocta, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 2 other files in mysql-replication-lag-resolver of openocta/openocta_skills.

  • SKILL.md
  • README.md
  • mate.json

Open the folder on GitHubat commit 6ac4479

Compare with similar skills

Mysql Replication Lag Resolver next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Mysql Replication Lag Resolver compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Mysql Replication Lag Resolver this skillopenocta/openocta_skills166—~2.6kAutomated safety check: PassMIT
Mysql Experttheneoai/awesome-skills183—~3.2kAutomated safety check: PassMIT
Mysql OptimizerFerroxLabs/wayland608—~3.5kAutomated safety check: PassApache-2.0
DB Ops SopOpenDCAI/DataMind406—~388Automated safety check: PassApache-2.0
Database Backupssickn33/agentic-awesome-skills47k2 repos~3.1kAutomated safety check: NotesMIT
MySQL Schema and Query Tuningplanetscale/database-skills6983 repos~1.4kAutomated safety check: PassMIT

Similar skills

  • Mysql Expert

    theneoai/awesome-skills

    MySQL expert with indexing optimization, InnoDB tuning, replication setup, and performance optimization.

    183 GitHub stars~3.2k tokensUpdated 4 mo ago
    DatabasesAuto-check passed
  • Mysql Optimizer

    FerroxLabs/wayland

    MySQL optimization expertise covering query optimization with EXPLAIN analysis, indexing strategies, InnoDB tuning, slow query log analysis, connection pooling, replication architectures…

    608 GitHub stars~3.5k tokensUpdated yesterday
    DatabasesAuto-check passed
  • DB Ops Sop

    OpenDCAI/DataMind

    Database operations runbook — backup, recovery, performance tuning, troubleshooting.

    406 GitHub stars~388 tokensUpdated 17 days ago
    DatabasesAuto-check passed
  • Database Backups

    sickn33/agentic-awesome-skills

    Implement database backup strategies. An agent skill from sickn33/agentic-awesome-skills.

    47k GitHub starsUsed in 2 repos~3.1k tokens
    DatabasesAuto-check: notes
  • MySQL Schema and Query Tuning

    planetscale/database-skills

    Official

    Guides safe, measurable MySQL and InnoDB changes across schema design, indexing, query tuning, transactions, locking and replication, with rollout steps.

    698 GitHub starsUsed in 3 repos~1.4k tokens
    DatabasesAuto-check passed
  • Vitess for PlanetScale

    planetscale/database-skills

    Official

    Guidance on Vitess sharding, VSchema design, query tuning and connection problems for MySQL-compatible databases running on PlanetScale.

    698 GitHub starsUsed in 1 repo~1.2k tokens
    DatabasesAuto-check passed

More from openocta/openocta_skills

All 8 skills in this repo
  • Mysql Full Inspection Skill

    openocta/openocta_skills

    对远程多实例MySQL数据库执行全方位深度巡检,覆盖基础健康、连接负载、性能慢查询、索引冗余、主从复制、容量空间、账号安全、配置风险八大维度,全自动完成巡检扫描、风险识别、问题定级、优化建议、报告归档与飞书推送,适用于生产/测试所有运行中MySQL实例常态化合规巡检。适用场景:用户要求进行 MySQL 全链路健康检查、MySQL 综合巡检、MySQL 风险扫描、MySQL 性能审计、MySQL…

    166 GitHub stars~2k tokensUpdated 3 mo ago
    Auto-check passed
  • Server Patrol

    openocta/openocta_skills

    Linux 与网络设备只读健康巡检;直接运行 scripts/patrol.sh,配置由平台侧信道注入,Agent 不读取环境变量

    166 GitHub stars~522 tokensUpdated 3 mo ago
    Auto-check passed
  • Wechat Gzh Analyzer

    openocta/openocta_skills

    分析微信公众号后台数据,包括文章阅读量、评论、点赞等统计。当用户需要分析微信公众号数据、导出公众号文章统计报表时调用此技能。

    166 GitHub stars~2.6k tokensUpdated 3 mo ago
    Auto-check passed
  • Mysql Deadlock Analyzer

    openocta/openocta_skills

    Full-chain MySQL deadlock analysis. An agent skill from openocta/openocta_skills.

    166 GitHub stars~2.2k tokensUpdated 3 mo ago
    Auto-check passed
  • Mysql Slow Query Diagnose

    openocta/openocta_skills

    Slow query diagnosis with root cause analysis and index optimization recommendations.

    166 GitHub stars~2.7k tokensUpdated 3 mo ago
    Auto-check passed
  • Tidb Cluster Inspector

    openocta/openocta_skills

    Comprehensive TiDB cluster inspection. An agent skill from openocta/openocta_skills.

    166 GitHub stars~2.9k tokensUpdated 3 mo ago
    Auto-check passed

Works with

Categories

Questions about Mysql Replication Lag Resolver

What does Mysql Replication Lag Resolver do?

Replication lag root cause analysis with automated resolution workflow. Mysql Replication Lag Resolver is an agent skill from openocta/openocta_skills. Replication lag root cause analysis with automated resolution workflow.

When should I use Mysql Replication Lag Resolver?

Mysql Replication Lag Resolver fits situations like: tasks that involve Database administration; tasks that involve GraphQL; tasks that involve Root cause analysis.

How do I install Mysql Replication Lag Resolver in Claude Code?

Run `npx skills add openocta/openocta_skills --skill mysql-replication-lag-resolver -a claude-code`. Or copy the skill folder (mysql-replication-lag-resolver in openocta/openocta_skills) into .claude/skills/mysql-replication-lag-resolver in your project. Claude Code loads it when a task matches its description.

How do I install Mysql Replication Lag Resolver in Codex?

Run `npx skills add openocta/openocta_skills --skill mysql-replication-lag-resolver -a codex`. Or copy the skill folder (mysql-replication-lag-resolver in openocta/openocta_skills) into .agents/skills/mysql-replication-lag-resolver in your project. Codex loads it when a task matches its description.

Can I use Mysql Replication Lag Resolver in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add openocta/openocta_skills --skill mysql-replication-lag-resolver -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/mysql-replication-lag-resolver, .gemini/skills/mysql-replication-lag-resolver, .github/skills/mysql-replication-lag-resolver and .opencode/skills/mysql-replication-lag-resolver in your project.

What does Mysql Replication Lag Resolver need to run?

SKILL.md names no scripts, command-line tools or credentials: Mysql Replication Lag Resolver is instructions for the agent only. Its frontmatter pre-approves these tools: db_query, db_get_status, db_get_processlist, db_kill_query.

Does Mysql Replication Lag Resolver access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Mysql Replication Lag Resolver safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Mysql Replication Lag Resolver use?

Mysql Replication Lag Resolver is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Mysql Replication Lag Resolver use?

About 2.6k tokens (SKILL.md is roughly 10k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Mysql Replication Lag Resolver?

Skills that share tags, products or a category with Mysql Replication Lag Resolver: Mysql Expert (theneoai/awesome-skills, 183 stars), Mysql Optimizer (FerroxLabs/wayland, 608 stars), DB Ops Sop (OpenDCAI/DataMind, 406 stars) and Database Backups (sickn33/agentic-awesome-skills, 47k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Mysql Replication Lag Resolver?

openocta (a GitHub user) maintains it in openocta/openocta_skills, which has 166 GitHub stars. The repository holds 8 skills in this directory. The repository was last updated on June 22, 2026.

Source: openocta/openocta_skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.