I want to have in my node information only about the last 300000 ledgers. Should I always manually clean the DB or can I automate it?

I'm especially interested in the autocleaning of the Horizon DB.

1 Answer 1


I found the answer while carefully reading again the admin guide's "Managing storage for historical data" section:

Over time, the recorded network history will grow unbounded, increasing storage used by the database. Horizon expands the data ingested from stellar-core and needs sufficient disk space. Unless you need to maintain a history archive you may configure Horizon to only retain a certain number of ledgers in the database. This is done using the --history-retention-count flag or the HISTORY_RETENTION_COUNT environment variable. Set the value to the number of recent ledgers you wish to keep around, and every hour the Horizon subsystem will reap expired data. Alternatively, you may execute the command horizon db reap to force a collection.

  • who has accepted this? My horizon disk is at 1TB and horizon db reap does nothing.
    – user83948
    Mar 1, 2021 at 19:51
  • Hey, what is the value of HISTORY_RETENTION_COUNT you have set? horizon db reap - reaps (i.e. removes) any reapable history data, as mentioned in the cli help message (horizon db --help). For example, if you set HISTORY_RETENTION_COUNT value to 1000 after execution of horizon db reap it will remove all blocks in the database and keep only latest 1000 blocks.
    – alexqrid
    Mar 3, 2021 at 13:48
  • As for the growing disk size, make sure that you have tuned POSTGRES AUTOVACUUM settings, for different tables it is better to tune it differently for big tables and small tables. You can read more about postgres autovacuum here and there
    – alexqrid
    Mar 3, 2021 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.