> Every playbook: https://protuno.com/playbooks.md · Site map for AI agents: https://protuno.com/llms.txt

# Database Optimisation

Clears database clutter in stages: a readiness check, a verified database backup, a count that flags anything unusual, a sweep through WordPress's own delete functions, a check afterwards and a final report.

- Agent: Dash (Performance)
- Steps: 8
- Changes the site: yes, in step 5
- Backup: Saves a backup or snapshot in step 2 (DB Smart Backup), before step 5 changes the site. Step 5 is also marked backup first.
- Connector: No connector needed
- You get: A written Markdown report of what was counted, cleared and rechecked, plus advice on reclaiming table space.
- Looks at: Revisions, auto drafts, trashed items and pending or spam comments; Transients, orphaned and duplicated metadata, unused terms and oEmbed cache; Tables with reclaimable space
- Page: https://protuno.com/playbooks/database-optimisation
- Ask: "Dash, run Database Optimisation on my site."

## Steps

1. **DB Preflight Readiness**: Checks the site is healthy, at least 200 MB is free for the backup, no other run is in progress and the last run did not end in a critical state.
2. **DB Smart Backup**: Saves a full database backup file in your uploads folder before anything is removed. It is not a copy kept off your server.
3. **Verify DB Backup**: Checks that the database backup is complete and readable before any clean up starts.
4. **Count And Anomaly Guard**: Counts each type of clutter and leaves out any type that is over half of its table. Posts with visitor comments are never swept.
5. **Sweep Safe Types**: Deletes the remaining clutter types one at a time with WordPress's own delete functions, after confirming the backup. Pending, spam and trashed comments are deleted permanently, and deleting a trashed or draft post also deletes its comments. `changes the site` `backup first`
6. **Post Sweep Verification**: Rechecks that each cleared type dropped, a few untouched types did not change, no published post or approved comment was lost and the site is still healthy.
7. **Optimize Tables Advisory**: Lists tables with space to reclaim and recommends how to reclaim it, without running any optimization.
8. **DB Final Report**: Writes the final report of what was cleared and how the run ended.

## Good to know

- Runs when you ask for it in your AI app. On Pro and Agency you can also put it on a routine.
- Needs no connector.
- Removes data in one step: the sweep step (step 5 of 8).
- Takes a database backup first and checks it before the clean up step.
- Does not run a table optimize itself; it only advises.
- Deletions are permanent. The database backup taken first is the only way to get the data back. Removing auto-drafts and trashed posts needs a force delete, which Protuno's safety guard refuses, so those are left in place.
- When it runs depends on the agent's mode: after you press Approve in Protuno in Approval mode, or on its own in Auto mode.
- There is no Roll back button for this playbook. Restoring means using the backup file.
- If the check after the sweep fails, the run is marked critical and the next run is blocked until that is cleared.

## How to run it
In an AI app connected to Protuno: `ask_agent` with the site and "Database Optimisation", then `propose_agent_plan`. In Approval mode, ask the user to press Approve in Protuno; in Auto mode the run starts when you propose it.
