Compact the LND database (channel.db)
An over 1GB channel.db file does not work on 32bit systems:
# check the size of channel.db
sudo du -h /mnt/hdd/lnd/data/graph/mainnet/channel.db
# example output
# 1.0G /mnt/hdd/lnd/data/graph/mainnet/channel.db

Auto-compact on restart

Since LND v0.12.0 can set in the lnd.conf.
  • To edit:
    sudo nano /mnt/hdd/lnd/lnd.conf
  • insert the following (can leave out the comments):
    # Whether the databases used within lnd should automatically be compacted on
    # every startup (and if the database has the configured minimum age). This is
    # disabled by default because it requires additional disk space to be available
    # during the compaction that is freed afterwards. In general compaction leads to
    # smaller database files.
    # How long ago the last compaction of a database file must be for it to be
    # considered for auto compaction again. Can be set to 0 to compact on every
    # startup. (default: 168h)
  • restart lnd:
    sudo systemctl restart lnd
  • monitor the process (can take several minutes):
    sudo tail -fn 30 /mnt/hdd/lnd/logs/bitcoin/mainnet/lnd.log
  • might want to disable the auto-compact in lnd.conf and only activate on-demand to avoid long startup times:

Compacting with Channels Tools

  • Run the following commands in the RaspiBlitz terminal
    See the comments for what each command does.
# install chantools
# download, inspect and run the install script
bash on
# stop lnd
sudo systemctl stop lnd
# change to the home directory of the bitcoin user
sudo su - bitcoin
# run the compacting
chantools compactdb --sourcedb /mnt/hdd/lnd/data/graph/mainnet/channel.db \
--destdb /mnt/hdd/lnd/data/graph/mainnet/compacted.db
# check the size of the compacted.db
# (the first compacting will have the biggest effect)
du -h /mnt/hdd/lnd/data/graph/mainnet/compacted.db
# example output:
# 730M /mnt/hdd/lnd/data/graph/mainnet/compacted.db
# make sure lnd is not runnning (needs sudo)
sudo systemctl stop lnd
sudo su - bitcoin
# backup the original database
mv /mnt/hdd/lnd/data/graph/mainnet/channel.db \
# move the compacted database in place of the old
mv /mnt/hdd/lnd/data/graph/mainnet/compacted.db \
# exit the bitcoin user to admin
# start lnd
sudo systemctl start lnd
# unlock the wallet
lncli unlock