Howto prune (shrink) the database of the Monero Blockchain on Linux

Howto prune (shrink) the database of the Monero Blockchain on Linux

By SolarEclipse | SolarEclipse | 29 Mar 2020


Monero

Howto prune the database of the Monero Blockchain

In this little tutorial, I will show you how to prune (equally shrink) the LMDB database, where Monero (XMR) stores it blockchain.

Why do you want to do this?

Obviously, because of the actual size of the LMDB database. The actual size today is already around 80G and growing daily. Even though today's limits on harddisk are very high and the prices for them are cheap, the handling of such big blockchains becomes more and more a mess. Think about your backups, the sizes of your virtual machines, migration times from one computer to another, and so on.

To facilitate scalability, Monero added since V. 0.14 release blockchain pruning to its daemon software. This feature allows you to optionally "prune" about 2/3 of the blockchain data, while still contributing to the network.

Pruning is the process of removing non-critical blockchain information from local storage. Full nodes keep an entire copy of everything that is stored on the blockchain, including data that is not very useful anymore. Pruned nodes remove much of this less relevant information to have a lighter footprint. Of course, running a full node is always better; however, pruned nodes have most of the important information and can still support the network.

 

Methods of pruning the Monero Blockchain

  • Run monerod with --prune-blockchain
  • Run prune_blockchain in the monerod console
  • Run the monero-blockchain-prune utility

The first two methods will prune in place and will not reduce the blockchain size on disk. Instead, it will mark parts of the file as free and future data can utilize the free space. If you use the first two methods, the resulting file will not grow until free space becomes scarce.

The third method will create a second database, which is a pruned copy of the original database. Because this method creates a new file, it will be smaller than the original. This tutorial is about pruning with the third method.

 

Where is your Monero database

On Linux, with a default installation of Monero, you can find your database at ~/.bitmonero/lmdb/. If you have defined a custom data directory when you installed Monero... you should now start to remember the path.

If you want to examine the size of your database, you can use the following commands.

du -h ~/.bitmonero/lmdb/data.mdb -> 80G

After the prune process, you will find your pruned database under ~/.bitmonero/lmdb-pruned/data.mdb.

 

Where is the monero-blockchain-prune utility

I found the monero-blockchain-prune utility in the subdirectory extras in my installation directory of the monero-wallet-gui.

 

Let's start to prune the database (best overnight)

First, note that pruning the database requires approximately 26-30 GB of additional storage, as, initially, the Monero software will store both the old non-pruned blockchain and the new pruned blockchain. You can, after verifying that your GUI runs properly, delete the old file of course. Second, you need some time for this process. Expect that pruning the database needs several hours and that you cannot use the wallet during this time. Best would be, that you prune the database while you sleep.

The following steps are required to prune your blockchain/database:

  • Close all Monero related processes.
  • Browse to the extras directory of your Monero installation.
  • Run ./monero-blockchain-prune
    • if you have used a custom data directory, you need to add
      --data-dir path/to/custom/data/directory at the end
  • If the blockchain is on a rotating drive, you will get this nice hint (which I ignored first)
    • The blockchain is on a rotating drive: this will be very slow, use an SSD if possible
  • After the monero-blockchain-prune tool has finished, open your monero-wallet-gui and verify that everything is running properly.
  • If yes -> You can now delete your old blockchain
    • rm -rf ~/.bitmonero/lmdb-old

 

The result

To verify the new size of your pruned blockchain, you can use the same command again but with the new database.

before pruning
du -h ~/.bitmonero/lmdb/data.mdb -> 80G

after pruning
du -h ~/.bitmonero/lmdb-pruned/data.mdb -> 26G

Pruning the Monero database with its blockchain saved me 54G disk space! Wow! If you use an SSD-Drive just right from the beginning, it is possible to do this job overnight. Once the database is pruned, it will stay pruned as it syncs. There is no need to prune the blockchain again.

 

Happy shrinking!!

 

Log:

2020-03-28 16:08:49.707 I Starting...
2020-03-28 16:08:49.707 I Initializing source blockchain (BlockchainDB)
2020-03-28 16:08:49.718 I Loading blockchain from folder "/home/XXXXX/.bitmonero/lmdb" ...
2020-03-28 16:08:49.719 W The blockchain is on a rotating drive: this will be very slow, use an SSD if possible
2020-03-28 16:09:40.923 I source blockchain storage initialized OK
2020-03-28 16:09:40.923 I Loading blockchain from folder "/home/XXXXX/.bitmonero/lmdb-pruned" ...
2020-03-28 16:09:40.923 W The blockchain is on a rotating drive: this will be very slow, use an SSD if possible
2020-03-28 16:09:41.039 I pruned blockchain storage initialized OK
2020-03-28 16:09:41.052 I Pruning...
2020-03-28 16:09:41.052 I Copying blocks
2020-03-28 16:25:13.587 I LMDB Mapsize increased. Old: 1024MiB, New: 1536MiB
2020-03-28 16:35:19.337 I Copying block_info
2020-03-28 16:44:01.179 I Copying block_heights
2020-03-28 16:47:09.531 I LMDB Mapsize increased. Old: 1536MiB, New: 2048MiB
2020-03-28 16:48:46.237 I Copying txs_pruned
2020-03-28 16:51:11.513 I LMDB Mapsize increased. Old: 2048MiB, New: 2562MiB
2020-03-28 16:54:26.152 I LMDB Mapsize increased. Old: 2562MiB, New: 3075MiB
2020-03-28 16:58:26.464 I LMDB Mapsize increased. Old: 3075MiB, New: 3587MiB
2020-03-28 17:02:53.171 I LMDB Mapsize increased. Old: 3587MiB, New: 4100MiB
2020-03-28 17:07:14.908 I LMDB Mapsize increased. Old: 4100MiB, New: 4612MiB
2020-03-28 17:11:07.458 I LMDB Mapsize increased. Old: 4612MiB, New: 5125MiB
2020-03-28 17:15:03.158 I LMDB Mapsize increased. Old: 5125MiB, New: 5637MiB
2020-03-28 17:19:16.784 I LMDB Mapsize increased. Old: 5637MiB, New: 6149MiB
2020-03-28 17:26:07.737 I LMDB Mapsize increased. Old: 6149MiB, New: 6661MiB
2020-03-28 17:35:42.159 I LMDB Mapsize increased. Old: 6661MiB, New: 7174MiB
2020-03-28 17:46:20.583 I LMDB Mapsize increased. Old: 7174MiB, New: 7686MiB
2020-03-28 17:47:41.301 I Copying txs_prunable_hash
2020-03-28 18:01:59.119 I Copying tx_indices
2020-03-28 18:05:23.160 I LMDB Mapsize increased. Old: 7686MiB, New: 8198MiB
2020-03-28 18:13:24.007 I LMDB Mapsize increased. Old: 8198MiB, New: 8710MiB
2020-03-28 18:17:14.602 I Copying tx_outputs
2020-03-28 18:23:14.138 I LMDB Mapsize increased. Old: 8710MiB, New: 9222MiB
2020-03-28 18:35:18.282 I Copying output_txs
2020-03-28 18:37:15.711 I LMDB Mapsize increased. Old: 9222MiB, New: 9734MiB
2020-03-28 18:45:14.685 I LMDB Mapsize increased. Old: 9734MiB, New: 10246MiB
2020-03-28 18:55:22.566 I LMDB Mapsize increased. Old: 10246MiB, New: 10758MiB
2020-03-28 19:13:46.162 I Copying output_amounts
2020-03-28 19:14:02.194 I LMDB Mapsize increased. Old: 10758MiB, New: 11270MiB
2020-03-28 19:26:07.528 I LMDB Mapsize increased. Old: 11270MiB, New: 11782MiB
2020-03-28 19:37:56.932 I LMDB Mapsize increased. Old: 11782MiB, New: 12294MiB
2020-03-28 19:53:47.670 I LMDB Mapsize increased. Old: 12294MiB, New: 12806MiB
2020-03-28 20:06:45.113 I LMDB Mapsize increased. Old: 12806MiB, New: 13318MiB
2020-03-28 20:14:32.215 I LMDB Mapsize increased. Old: 13318MiB, New: 13830MiB
2020-03-28 20:20:48.698 I Copying spent_keys
2020-03-28 20:24:49.201 I LMDB Mapsize increased. Old: 13830MiB, New: 14342MiB
2020-03-28 20:34:05.571 I LMDB Mapsize increased. Old: 14342MiB, New: 14854MiB
2020-03-28 20:41:03.871 I LMDB Mapsize increased. Old: 14854MiB, New: 15367MiB
2020-03-28 20:48:34.715 I LMDB Mapsize increased. Old: 15367MiB, New: 15879MiB
2020-03-28 20:53:40.371 I Copying txpool_meta
2020-03-28 20:53:40.415 I Copying txpool_blob
2020-03-28 20:53:40.455 I Copying hf_versions
2020-03-28 20:55:47.069 I Copying properties
2020-03-28 20:55:47.085 I Creating pruned txs_prunable
2020-03-28 21:15:40.567 I LMDB Mapsize increased. Old: 15879MiB, New: 16393MiB
2020-03-28 22:52:01.753 I LMDB Mapsize increased. Old: 16393MiB, New: 16910MiB
2020-03-29 00:36:52.054 I LMDB Mapsize increased. Old: 16910MiB, New: 17424MiB
2020-03-29 02:27:37.307 I LMDB Mapsize increased. Old: 17424MiB, New: 17937MiB
2020-03-29 04:21:25.975 I LMDB Mapsize increased. Old: 17937MiB, New: 18450MiB
2020-03-29 06:21:32.390 I LMDB Mapsize increased. Old: 18450MiB, New: 18963MiB
2020-03-29 08:26:37.177 I LMDB Mapsize increased. Old: 18963MiB, New: 19477MiB
2020-03-29 10:33:59.898 I LMDB Mapsize increased. Old: 19477MiB, New: 19990MiB

 

Here I paused my VM and moved it to a SSD-Drive... ;)

 


2020-03-29 13:27:37.805 I LMDB Mapsize increased. Old: 19990MiB, New: 20506MiB
2020-03-29 13:34:46.141 I LMDB Mapsize increased. Old: 20506MiB, New: 21021MiB
2020-03-29 13:41:54.202 I LMDB Mapsize increased. Old: 21021MiB, New: 21533MiB
2020-03-29 13:49:09.198 I LMDB Mapsize increased. Old: 21533MiB, New: 22047MiB
2020-03-29 13:56:25.303 I LMDB Mapsize increased. Old: 22047MiB, New: 22560MiB
2020-03-29 14:03:54.841 I LMDB Mapsize increased. Old: 22560MiB, New: 23073MiB
2020-03-29 14:11:19.767 I LMDB Mapsize increased. Old: 23073MiB, New: 23587MiB
2020-03-29 14:18:50.494 I LMDB Mapsize increased. Old: 23587MiB, New: 24100MiB
2020-03-29 14:26:22.526 I LMDB Mapsize increased. Old: 24100MiB, New: 24615MiB
2020-03-29 14:33:36.875 I LMDB Mapsize increased. Old: 24615MiB, New: 25128MiB
2020-03-29 14:40:45.945 I LMDB Mapsize increased. Old: 25128MiB, New: 25642MiB
2020-03-29 14:47:55.226 I LMDB Mapsize increased. Old: 25642MiB, New: 26154MiB
2020-03-29 14:55:03.655 I LMDB Mapsize increased. Old: 26154MiB, New: 26668MiB
2020-03-29 15:02:13.744 I LMDB Mapsize increased. Old: 26668MiB, New: 27183MiB
2020-03-29 15:02:13.744 I LMDB Mapsize increased. Old: 26668MiB, New: 27183MiB
2020-03-29 15:07:09.509 I Swapping databases, pre-pruning blockchain will be left in /home/XXXXXX/.bitmonero/lmdb-old and can be removed if desired
2020-03-29 15:07:09.518 I Blockchain pruned OK


SolarEclipse
SolarEclipse

Believing that crypto is changing our world. To the better or to the worse? We will see!


SolarEclipse
SolarEclipse

In this blog, I write about my findings in the crypto world.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.