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.mdCopy 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
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
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 likept-online-schema-changeorgh-ostto 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
Comments
- …
More skills from this repository
analyze_buffer_pool
9.5kHelps your database agent check how well MySQL or MariaDB uses its InnoDB memory cache, spot disk write stalls and suggest a sensible buffer pool size.
cli-execution-mastery
9.5kHelps your agent run the MySQLTuner health check with the right connection and login options, for local, remote or container databases.
diagnose_replication_lag
9.5kHelps your agent check whether a MySQL or MariaDB replica has fallen behind its main server, and find any failed replication threads and their errors.
Similar skills
discrawl
394kLets your agent search and summarize a saved local archive of Discord messages, check how fresh it is, and read direct messages.
clickhouse-io
280kHelps your agent optimize queries and schemas in ClickHouse databases. It applies best practices for high-performance analytical workloads. Use when analytical queries are too slow.
scientific-db-pubmed-database
280kHelps your agent search for scientific articles in the biomedical field. It's useful for research needing specific medical information.