hedera-mirror-cleanup
This is a simple Golang application that executes SQL commands to clean up a mirror node's database. Depending on your mirror node's configuration and your specific use case, you may be storing a lot of data that you don't need. This data can be cleaned up to minimise disk usage.
For example, if balances are enabled on the importer, it will add hundreds of thousands or even millions of rows to the account_balance and token_balance tables every 15 minutes. You may need the latest balances but not historical balances, in which case you could run this application to delete old balance data while keeping the new data.
Default commands
The commands included in the application delete all rows in the account_balance, token_balance, and record_file tables that have a consensus_timestamp/consensus_start less than the maximum (latest) value in the table.
It also deletes all rows in the crypto_transfer and transaction tables where the consensus_timestamp is less than or equal to the current time stamp minus 24 hours.
Finally, it performs a full vacuum on these tables to free up disk space.
Altering the commands
You can change the commands to suit your needs by modifying them in the functions.go
file.
Usage
Clone the repo and modify the commands to suit your needs.
Build the binary for the platform you'll be executing it from.
Create a .env file with the following information
DB_USER=
DB_PASS=
DB_HOST=
DB_PORT=
DB_NAME=
If you want the application to run periodically, you can set up a cron job.