Compact the LND database (channel.db)
An over 1GB channel.db file does not work on 32bit systems: https://github.com/lightningnetwork/lnd/issues/4811
1
# check the size of channel.db
2
sudo du -h /mnt/hdd/lnd/data/graph/mainnet/channel.db
3
# example output
4
# 1.0G /mnt/hdd/lnd/data/graph/mainnet/channel.db
Copied!

Auto-compact on restart

Since LND v0.12.0 can set db.bolt.auto-compact=true in the lnd.conf.
  • To edit:
    sudo nano /mnt/hdd/lnd/lnd.conf
  • insert the following (can leave out the comments):
    1
    [bolt]
    2
    # Whether the databases used within lnd should automatically be compacted on
    3
    # every startup (and if the database has the configured minimum age). This is
    4
    # disabled by default because it requires additional disk space to be available
    5
    # during the compaction that is freed afterwards. In general compaction leads to
    6
    # smaller database files.
    7
    db.bolt.auto-compact=true
    8
    # How long ago the last compaction of a database file must be for it to be
    9
    # considered for auto compaction again. Can be set to 0 to compact on every
    10
    # startup. (default: 168h)
    11
    # db.bolt.auto-compact-min-age=0
    Copied!
  • 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:
    1
    db.bolt.auto-compact=false
    Copied!

Compacting with Channels Tools

  • Run the following commands in the RaspiBlitz terminal
    See the comments for what each command does.
1
# install chantools
2
# download, inspect and run the install script
3
wget https://raw.githubusercontent.com/openoms/lightning-node-management/master/lnd.updates/bonus.chantools.sh
4
cat bonus.chantools.sh
5
bash bonus.chantools.sh on
6
7
# stop lnd
8
sudo systemctl stop lnd
9
10
# change to the home directory of the bitcoin user
11
sudo su - bitcoin
12
13
# run the compacting
14
chantools compactdb --sourcedb /mnt/hdd/lnd/data/graph/mainnet/channel.db \
15
--destdb /mnt/hdd/lnd/data/graph/mainnet/compacted.db
16
17
# check the size of the compacted.db
18
# (the first compacting will have the biggest effect)
19
du -h /mnt/hdd/lnd/data/graph/mainnet/compacted.db
20
# example output:
21
# 730M /mnt/hdd/lnd/data/graph/mainnet/compacted.db
22
23
# make sure lnd is not runnning (needs sudo)
24
exit
25
sudo systemctl stop lnd
26
sudo su - bitcoin
27
28
# backup the original database
29
mv /mnt/hdd/lnd/data/graph/mainnet/channel.db \
30
/mnt/hdd/lnd/data/graph/mainnet/uncompacted.db
31
32
# move the compacted database in place of the old
33
mv /mnt/hdd/lnd/data/graph/mainnet/compacted.db \
34
/mnt/hdd/lnd/data/graph/mainnet/channel.db
35
36
# exit the bitcoin user to admin
37
exit
38
39
# start lnd
40
sudo systemctl start lnd
41
42
# unlock the wallet
43
lncli unlock
Copied!
Last modified 28d ago