Why is the Bitcoin Core wallet moving from Berkeley DB to SQLite for its database backend?
1 Answer
The introduction of descriptor wallets presents an opportunity to introduce a new database backend as descriptor wallets are backwards incompatible. The following is taken from Andrew Chow's blog post on what's coming to the Bitcoin Core wallet in 0.21. (There was also discussion on this GitHub Issue.)
Why move from Berkeley DB?
- Not designed to be used as an application data file. The Legacy Wallet has several hacks to get round this as a result and Berkeley DB wallet files can easily be corrupted.
- Berkeley DB produces extra files which need to be moved with the database file. This means that Berkeley DB is less portable and requires a directory for each wallet.
- Changes were introduced to Berkeley DB database environment files breaking backwards compatibility.
Why choose SQLite?
Can be used as an application data file.
New SQLite versions maintains backwards compatibility with versions as far back as 2013.
Does not require database environment. A completed write guarantees that the data was written to the database file.
Can now move to single wallet files instead of wallet directories.
Here is the proposed timeline for legacy wallet and Berkeley DB removal from Bitcoin Core.
-
8There is also the fact that SQLite is easily the most robust, reliable, and heavily tested DB engine. It is probably also some of the most robust, reliable, and heavily tested code, period, except maybe the aerospace industry. Maybe even better (cough Boeing cough). Their testing regime and approach to robustness and reliability is truly insane. For each line of code, there are 640 lines of tests. Commented Oct 25, 2020 at 7:39