Skip to content
Skillpedia
Databases9.5k · #12278

detect_fragmented_tables

What it does

This skill looks for MySQL and MariaDB tables that hold unused space and estimates how much could be reclaimed. It is for database admins who want to cut storage use safely.

When to use it

  • ✓When your database disk is filling up and you want to know where the waste is.
  • ✓When a table has a lot of free space that could be reclaimed.
  • ✓When you are planning maintenance and need to know which tables are large enough to affect the server.

Skill link

https://github.com/major/MySQLTuner-perl/blob/master/.agent/skills/detect-fragmented-tables/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/major/MySQLTuner-perl/blob/master/.agent/skills/detect-fragmented-tables/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“Find the tables in my database that waste the most disk space and tell me which are safe to clean up.”

5 new skills a week. 1 minute to read.

How it works

The agent reads table size information, calculates the share of free space in each table, and ranks the results. It suggests cleanup commands and flags large tables as high impact so you can plan around them.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

AI Skill: Table Fragmentation & Storage Reclaim Diagnostics

🧠 Purpose & Operational Objectives

The detect_fragmented_tables skill enables autonomous DBA agents to identify wasted disk space, high data file fragmentation, and unused allocated extents across InnoDB and MyISAM tables.

📋 Preconditions & Context

  • Server running MySQL 5.5+ or MariaDB 10.0+.
  • Read access to information_schema.TABLES.
  • Evaluates non-system schemas (skips mysql, information_schema, performance_schema, sys).

🛠️ Input Parameters

Parameter Type Required Default Description
min_fragmentation_pct number No 20 Minimum fragmentation percentage (0-100) to trigger reporting.
min_table_size_mb number No 10 Minimum table size in MB to filter out trivial tables.
schema_filter string No "" Optional schema name to restrict the scan.

📊 Fragmentation Formula & Impact Scoring

$$\text{Total Allocated Space} = \text{DATA_LENGTH} + \text{INDEX_LENGTH} + \text{DATA_FREE}$$ $$\text{Fragmentation Pct} = \left(\frac{\text{DATA_FREE}}{\text{Total Allocated Space}}\right) \times 100$$

  • Tables $< 5\text{GB}$: Can be defragmented online during low-traffic windows via OPTIMIZE TABLE \db`.`table`;`.
  • Tables $\ge 5\text{GB}$: Flagged as is_high_impact: true. Advise using online tools like pt-online-schema-change or gh-ost to prevent extended table locks and disk thrashing.

🛡️ Guardrails & Safety

  • All schema and table names are safely escaped with backticks to prevent SQL injection.
  • Reclaimable disk space is calculated deterministically.
FAQ

Does it clean up tables by itself?

It reports and suggests commands. You review them before running anything on your database.

Which tables does it skip?

System schemas such as mysql, information_schema, performance_schema and sys are not scanned.

Can I narrow the scan?

Yes. You can set a minimum fragmentation percentage and table size, or limit the scan to one schema.

Details

Original description by the author

Detects tables with high storage fragmentation, calculates reclaimable disk space, evaluates lock impact, and generates safe defragmentation commands.

repo: major/MySQLTuner-perl

Popularity

GitHub stars
9.5k
Ranking position
#12278
License
GPL-3.0
Updated
10/28/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills