Reduce GETH ETH Node Disk Space Usage
So, I have a ETH2 validator node which uses a Hetzner AX41 dedicated server and has been running since genesis. The set-up includes a GETH ETH1 node, beacon chain and the ETH2 Validator (Prysm) and is slowly using the allocated 1TB NVMe disk space (2 x 512GB using RAID 0). I reached out to the Prysm Discord channel to seek advice and what is best to do. A very friendly chap replied and I thought it useful to share in case anyone else has the same challenge.
Simple way to prune GETH diskspace
Beacon-node set-up #Set-up Beacon-chain failover for infura.io free or alchemy.io free.#Prylabs fallback eth1 nodes documentation.
http-web3provider: http://localhost:8545
fallback-web3provider:
- https://mainnet.infura.io/v3/YOUR-PROJECT-ID
- https://eth-mainnet.alchemyapi.io/v2/YOUR-PROJECT-ID
#Restart Beacon-nodesudo service beacon-node restart
#Check Beacon-node service statussudo service beacon-node status
#Check Beacon-node service logs for activitysudo journalctl -fu beacon-node
Geth node pruning #Check location of Geth working directory
cat /etc/systemd/system/geth.service
#Get current size of GETH data locationdu -sh <WorkingDirectory>
#Stop Gethsudo service geth stop
#Change Service to Prunevi /etc/systemd/system/geth.service
[Comment out existing ExecStart using a #]#ExecStart=/usr/bin/geth blah blah blah
[Add new ExecStart to prune]ExecStart=/usr/bin/geth snapshot prune-state
#Reload Service configsudo systemctl daemon-reload
#Start Geth Pruningsudo service geth start
#Check Geth service statussudo service geth status
#Check Geth service logs for pruning activitysudo journalctl -fu geth
Logs should look something like this and can take up to 4 hours to complete… Once pruning and dB compacting has finished... #Stop Geth in Pruning modesudo service geth stop
vi /etc/systemd/system/geth.service
[Uncomment the normal ExecStart removing the #]ExecStart=/usr/bin/geth blah blah blah
[Comment out the ExecStart to prune with an #]#ExecStart=/usr/bin/geth snapshot prune-state
#Reload Service configsudo systemctl daemon-reload
#Start Geth in normal modesudo service geth start
#Check Geth service statussudo service geth status
#Check Geth service logs for normal activitysudo journalctl -fu geth
#Check current size of GETH data location
du -sh <WorkingDirectory>
Boom!
Useful commands
If you encounter any errors during the pruning, then you may wish to consider starting a fresh and removing the Geth chain data. There is a formal and easy way to remove the data and start again, but sometimes Geth can get mixed up if a previous Geth has been running and created multiple chain data folders. In this scenario, you can manually remove the folder and Geth will sync from day one.
NB: Geth working directory when running within a service is typically "/home/geth/"
Formal removal of Geth Chaindata
#Stop Geth in normal modesudo service geth stop
#Remove Geth database (chaindata) NB: Ensure that the prompted Geth working directory is what you expect it to be. If its not, then you may consider the informal method for removing the Geth chaindata. geth removedb
#Start Geth in normal modesudo service geth start
#Check Geth service logs for normal activitysudo journalctl -fu geth
#Check current size of GETH data location
du -sh <WorkingDirectory>
Boom!
Informal removal of Geth Chaindata
#Stop Geth in normal modesudo service geth stop
#manually remove Geth database (chaindata) NB: Ensure the correct path is used for the Geth working directory (/home/geth/ used in this example sudo rm -rf /home/geth/.ethereum/geth/chaindata/
#Start Geth in normal modesudo service geth start
#Check Geth service logs for normal activitysudo journalctl -fu geth
#Check current size of GETH data location
du -sh <WorkingDirectory>
Boom!