According to this Bitcoin stores the user's keys and some additional data in a file called wallet.dat, which is a Berkley DB. Let's suppose the wallet.dat contained only the user's keys. Let's also suppose we're using linux.

What is then the main reason for Bitcoin to store keys in a database? Wouldn't it have the same effect if keys were stored as flat files: the public key would be the filename and the private key would be the content of the file?

Even if we had millions of keys, and therefore millions of files in a single directory, the i-node limit (maximum number of files in a directory) and file lookup speed shouldn't be a problem. The majority of linux systems use the ext4 as its filesystem and according to this the number of i-nodes in ext4 is unlimited (limited only by the disk memory). Also according to this the EXT4 uses a structure called HTree, which allows for file lookups to have a constant time complexity.

1 Answer 1


Historically bdb was used for the UTXO as well, so you could justify using it for the wallet as well for consistency. It makes absolutely no sense today, other than that it will always need to be supported to some extent for compatibility.

Really the wallet could be replaced with any key value store at all and it would function completely fine. You would not want a single key per file because this tends to be incredibly inefficient and difficult to deal with from a filesystem, and a human interaction perspective. It's easier to back up a single file than tens of thousands in a directory.

  • Could you be more specific about a single key per file being inefficient and difficult to dealt with from a FS, and a human interaction perspective? Does that only include backing up the files? Also by easier to back up, do you mean easier from the user perspective? I can imagine that If I'd use a GUI, copying tens of thousands of files to create a backup would be difficult and not user-friendly. But if I used a CLI, it wouldn't be much of a problem. All I would need to do is use the command cp wallet_keys/* <destination_directory>.
    – Aschente
    Commented Jun 8, 2020 at 16:09
  • 3
    @Aschente How would you know whether you had them all? A single file has useful properties such as a size, a last modified date, and so on. Dealing with, potentially, thousands of files is a nightmare. And what if you have multiple wallets and want to switch between them? Commented Jun 8, 2020 at 18:28
  • @David Schwartz I see, that's a good point.
    – Aschente
    Commented Jun 8, 2020 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.