erigon-mdbx-compact

Compact an MDBX database file to reclaim garbage-collected pages and shrink disk usage.

3.6k|1.5k|Updated May 27, 2019
One-click install
npx skills add https://github.com/erigontech/erigon --skill erigon-mdbx-compact
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: erigon-mdbx-compact
Source: https://github.com/erigontech/erigon/tree/main/.claude/skills/erigon-mdbx-compact
Command: npx skills add https://github.com/erigontech/erigon --skill erigon-mdbx-compact

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Erigon's MDBX chaindata database accumulates reclaimable pages over time, causing mdbx.dat to grow far beyond its useful data size and potentially triggering MDBX_MAP_FULL errors. This Skill compacts the database by copying it without garbage-collected pages, producing a smaller on-disk file.

Core Features & Use Cases

  • Database Compaction: Copies <datadir>/chaindata with mdbx_copy into a compacted mdbx.dat, excluding reclaimable pages.
  • Safety Validation: Verifies the database file exists, checks that free disk space exceeds the current mdbx.dat size, and requires Erigon and rpcdaemon to be stopped before proceeding.
  • Optional Diagnosis: Runs mdbx_stat -ef to show the Reclaimable percentage so you can decide whether compaction is worthwhile.
  • Use Case: Your archive node's mdbx.dat has grown to hundreds of gigabytes and mdbx_stat shows 40% reclaimable space. Use this Skill to build mdbx_copy, compact the database in the background, swap in the compacted file, and verify the new size before restarting Erigon.

Quick Start

Compact the MDBX database in my Erigon datadir at /var/lib/erigon to reclaim free space and shrink mdbx.dat.

Frequently Asked Questions about erigon-mdbx-compact

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I shrink the Erigon mdbx.dat database file?

Stop Erigon and rpcdaemon, build the tools with make db-tools, then run mdbx_copy -c with the chaindata directory as source and a new file path as destination. After it completes, delete the old mdbx.dat and mdbx.lck, move the compacted file into place, and restart Erigon.

How do I fix an MDBX_MAP_FULL error in Erigon?

MDBX_MAP_FULL indicates the database has exhausted its mapped space, often due to accumulated reclaimable pages. Compacting the database with mdbx_copy rewrites it without garbage-collected pages, producing a smaller file that resolves the condition.

How much free disk space does MDBX compaction need?

You need roughly 2x the current mdbx.dat size in free space, because the compacted copy is written alongside the original before the old file is deleted. The procedure checks available space with df and aborts if it is insufficient.

Can I compact the MDBX database while Erigon is running?

No. Erigon and rpcdaemon must be stopped before compaction because the database must not be in use. Always confirm the node is fully shut down before running mdbx_copy.

How do I check if MDBX compaction is worthwhile?

Run make db-tools, then execute mdbx_stat -ef on the chaindata directory. The Reclaimable line in the output shows the percentage of pages that compaction would recover, letting you estimate space savings before committing to the process.