<h1>db_dump</h1>
<p>You can use <code>db_dump</code> from the Berkeley <code>db-utils</code> package.</p>
<p>I've used that under Windows-10 by using WSL (Ubuntu) - It can definitely dump an unencrypted Bitcoin <code>wallet.dat</code> file.</p>
<p>The Berkeley DB libraries used by Bitcoin core for the <code>wallet.dat</code> are a key-value store - and the keys used appear to be words like &quot;key&quot; and &quot;keymeta&quot;.</p>
<p>As far as I know, the structure (if not simple data types) of the key and value are not known to the DB libraries. I believe applications such as Bitcoin core will often be storing blobs whose contents cannot be dissected by general tools which lack knowledge of the applications' schema.  The same observations are likely to apply to sqlite browser</p>
<p>However <code>db_dump</code> output is a worthwhile step up from a hex dump! The <code>-p</code> or <code>-da</code> options may be useful.</p>
<hr />
<h1>SQLite</h1>
<p><a href="https://github.com/bitcoin/bitcoin/pull/19077" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/pull/19077</a> says</p>
<blockquote>
<p>This PR adds a new class SQLiteDatabase which is a subclass of WalletDatabase. This provides access to a SQLite database that is used to store the wallet records. To keep compatibility with BDB and to complexity of the change down, we don't make use of many SQLite's features. We use it strictly as a key-value store. We create a table main which has two columns, key and value both with the type blob.</p>
</blockquote>
<p>...</p>
<blockquote>
<p>We keep the name wallet.dat for SQLite wallets. We are able to determine which database type to use by searching for specific magic bytes in the wallet.dat file. SQLite begins it's files with a null terminated string <code>SQLite format 3</code>. BDB has <code>0x00053162</code> at byte 12 (note that the byte order of this integer depends on the system endianness). So when we see that there is a wallet.dat file that we want to open, we check for the magic bytes to determine which database system to use.</p>
</blockquote>
<p>I'm using current Bitcoin core 0.21.0, but the wallet I examined was first generated in 2018 and has the Berkeley DB (BDB) signature. Bitcoin core has not rewritten the file in a newer/different format.</p>
<p><a href="https://github.com/bitcoin/bitcoin/issues/20160" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/issues/20160</a> provides a timeline for the phasing out of Berkely DB (which obviously affects the contents of this answer)</p>
<hr />
<h1>Wallet.dat</h1>
<p>My brief examination of a wallet.dat backup using a hex-dump suggested that the wallet mostly contains private keys, addresses generated and some sparse metadata about each.</p>
<p>See also</p>
<ul>
<li><a href="https://bitcoin.stackexchange.com/q/101767/13866">dumpwallet output documentation &amp; explanation?</a> (2021 and relevant)</li>
<li><a href="https://bitcoin.stackexchange.com/q/853/13866">What do the different .dat files contain?</a> (2011, ∴ limited usefulness)</li>
<li><a href="https://bitcoin.stackexchange.com/q/57978/13866">File format -- rev*.dat</a> (2017, interesting but different file)</li>
<li><a href="https://bitcoin.stackexchange.com/q/11104/13866">What is the database for?</a> (2013, ∴ limited usefulness)</li>
<li><a href="https://bitcoin.stackexchange.com/q/61907/13866">UXTO DB structure</a> (2017, not relevant but interesting documentation)</li>
</ul>
<blockquote>
<p>wallet.dat contains your private keys, your address book, a copy of the transactions that send coins from or to one of your addresses, accounts, reserve keys, personal settings, and a pointer to the current best block.</p>
</blockquote>
<p>(Note: Bitcoin core's &quot;accounts&quot; feature was deprecated some years ago)</p>

CC BY-SA 4.0
2021-03-08T14:31:15.800Z
New wallets are using SQLite, since the OP mentioned it they probably using that so i doubt a Berkeley DB tool would work for their use case
Antoine Poinsot
CC BY-SA 4.0
2021-03-08T14:33:51.677Z
@darosier, AIUI Bitcoin core uses different libraries for the wallet file than for the other files. https://github.com/bitcoin/bitcoin/issues/20160
RedGrittyBrick
CC BY-SA 4.0
2021-03-08T14:35:57.670Z
I ran `db_dump` on the already backed up wallet.dat (sqlite) and it did dump some interesting info ie. I the name of the db 'main' and the keys. I guess thats pretty much all there is in the wallet..? Was hoping to see a visual depiction of the db. I haven't marked this answer as correct yet as I still would like to know which password / key the browser is wanting
leo_cape
CC BY-SA 4.0
2021-03-08T14:43:47.883Z
@leo: I'd guess it *needs* the password used to encrypt the key values (if you protected the wallet.dat with a password) But I don't know if Bitcoin Core uses some global encryption provided by the DB library or whether it applies its own encryption to the relevant value contents only (I thought it was the latter but don't actually know for sure). I surmise SQlite might be asking for a global DB password which doesn't apply, might be doing so because it is confused or might be doing so because it wants you to decide if one is needed. I'm not familiar with SQlite
RedGrittyBrick
CC BY-SA 4.0
2021-03-08T14:20:33.267Z
2021-03-08T16:15:42.127Z
2021-03-08T16:15:42.127Z
RedGrittyBrick
<p>I backed up my wallet.dat using the command as mentioned in the api ref:</p>
<p><code>bitcoin-cli -rpcport=18332 -rpcuser=user -rpcpassword=password backupwallet &quot;/bitcoin/backup.dat&quot;</code></p>
<p>I would like to view the backed-up db file using 'DB browser for sqlite' (or any other sqlite browser). However when opening the db file it prompts for the password / key to decrypt the wallet file.</p>
<p>Which password / key is it referring to? When creating the backup I didnt specify any password or key..</p>
<p><a href="https://i.sstatic.net/H2i35.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/H2i35.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2021-03-08T13:49:05.273Z
Is there any reason you don't use `db_dump` from the Berkeley `db-utils` package? I've used that under Windows-10 by using WSL (Ubuntu) - It can definitely dump an unencrypted Bitcoin `wallet.dat` file. I imagine it might even be easier to install and use `db-utils` under OSX - if that's your operating system.
RedGrittyBrick
CC BY-SA 4.0
2021-03-08T14:05:15.367Z
Well the wallet.dat is from an Ubuntu server running Bitcoin-core that I am then opening on the OSX machine after the backup.. I hadn't known about the Berkeley `db-utils` package, can the `db_dump` util be safely run against a live running node? Or could it be run against the already backed up wallet.dat file?
leo_cape
CC BY-SA 4.0
2021-03-08T14:10:06.360Z
I ran it against a backed up wallet.dat - not one that was being actively used.
RedGrittyBrick
CC BY-SA 4.0
2021-03-08T14:12:40.363Z
Thanks @RedGrittyBrick works well, didn't know this package existed! I guess the wallet.dat is just made up of a 'main' db/schema and the keys inside it, I was hoping to see visually what else was contained in it, but it looks like only keys and some meta
leo_cape
CC BY-SA 4.0
2021-03-08T14:19:46.500Z
OK I'll post my comment as an answer
RedGrittyBrick
CC BY-SA 4.0
2021-11-22T18:59:10.030Z
wallets only use SQLite in limited circumstances.  To make an SQLite wallet run Bitcoin Core version v0.21 or v22.0 then create a new descriptor wallet; https://github.com/bitcoin/bitcoin/blob/9a42b5e/doc/release-notes/release-notes-0.21.0.md#sqlite-database-backend
Dan
<bitcoin-core><backup><passphrase>
View backed up wallet.dat using sqlite browser
leo_cape
# View backed up wallet.dat using sqlite browser

(Asked by: username_0 on 2021-03-08)

I backed up my wallet.dat using the command as mentioned in the api ref:

`bitcoin-cli -rpcport=18332 -rpcuser=user -rpcpassword=password backupwallet "/bitcoin/backup.dat"`

I would like to view the backed-up db file using 'DB browser for sqlite' (or any other sqlite browser). However when opening the db file it prompts for the password / key to decrypt the wallet file.

Which password / key is it referring to? When creating the backup I didnt specify any password or key..

[![enter image description here](https://i.sstatic.net/H2i35.png)](https://i.sstatic.net/H2i35.png)

**Tags:** bitcoin-core, backup, passphrase

> **Comments:**
> **username_1**: Is there any reason you don't use `db_dump` from the Berkeley `db-utils` package? I've used that under Windows-10 by using WSL (Ubuntu) - It can definitely dump an unencrypted Bitcoin `wallet.dat` file. I imagine it might even be easier to install and use `db-utils` under OSX - if that's your operating system.  
> **username_0**: Well the wallet.dat is from an Ubuntu server running Bitcoin-core that I am then opening on the OSX machine after the backup.. I hadn't known about the Berkeley `db-utils` package, can the `db_dump` util be safely run against a live running node? Or could it be run against the already backed up wallet.dat file?  
> **username_1**: I ran it against a backed up wallet.dat - not one that was being actively used.  
> **username_0**: Thanks @username_1 works well, didn't know this package existed! I guess the wallet.dat is just made up of a 'main' db/schema and the keys inside it, I was hoping to see visually what else was contained in it, but it looks like only keys and some meta  
> **username_1**: OK I'll post my comment as an answer  
> **username_2**: wallets only use SQLite in limited circumstances.  To make an SQLite wallet run Bitcoin Core version v0.21 or v22.0 then create a new descriptor wallet; https://github.com/bitcoin/bitcoin/blob/9a42b5e/doc/release-notes/release-notes-0.21.0.md#sqlite-database-backend  

---

## 1 answers

### Answer by username_1 on 2021-03-08. Score: 1 | Accepted answer

# db\_dump

You can use `db_dump` from the Berkeley `db-utils` package.

I've used that under Windows-10 by using WSL (Ubuntu) - It can definitely dump an unencrypted Bitcoin `wallet.dat` file.

The Berkeley DB libraries used by Bitcoin core for the `wallet.dat` are a key-value store - and the keys used appear to be words like "key" and "keymeta".

As far as I know, the structure (if not simple data types) of the key and value are not known to the DB libraries. I believe applications such as Bitcoin core will often be storing blobs whose contents cannot be dissected by general tools which lack knowledge of the applications' schema. The same observations are likely to apply to sqlite browser

However `db_dump` output is a worthwhile step up from a hex dump! The `-p` or `-da` options may be useful.

---

# SQLite

<https://github.com/bitcoin/bitcoin/pull/19077> says

> This PR adds a new class SQLiteDatabase which is a subclass of WalletDatabase. This provides access to a SQLite database that is used to store the wallet records. To keep compatibility with BDB and to complexity of the change down, we don't make use of many SQLite's features. We use it strictly as a key-value store. We create a table main which has two columns, key and value both with the type blob.

...

> We keep the name wallet.dat for SQLite wallets. We are able to determine which database type to use by searching for specific magic bytes in the wallet.dat file. SQLite begins it's files with a null terminated string `SQLite format 3`. BDB has `0x00053162` at byte 12 (note that the byte order of this integer depends on the system endianness). So when we see that there is a wallet.dat file that we want to open, we check for the magic bytes to determine which database system to use.

I'm using current Bitcoin core 0.21.0, but the wallet I examined was first generated in 2018 and has the Berkeley DB (BDB) signature. Bitcoin core has not rewritten the file in a newer/different format.

<https://github.com/bitcoin/bitcoin/issues/20160> provides a timeline for the phasing out of Berkely DB (which obviously affects the contents of this answer)

---

# Wallet.dat

My brief examination of a wallet.dat backup using a hex-dump suggested that the wallet mostly contains private keys, addresses generated and some sparse metadata about each.

See also

* [dumpwallet output documentation & explanation?](https://bitcoin.stackexchange.com/q/101767/13866) (2021 and relevant)
* [What do the different .dat files contain?](https://bitcoin.stackexchange.com/q/853/13866) (2011, ∴ limited usefulness)
* [File format -- rev\*.dat](https://bitcoin.stackexchange.com/q/57978/13866) (2017, interesting but different file)
* [What is the database for?](https://bitcoin.stackexchange.com/q/11104/13866) (2013, ∴ limited usefulness)
* [UXTO DB structure](https://bitcoin.stackexchange.com/q/61907/13866) (2017, not relevant but interesting documentation)

> wallet.dat contains your private keys, your address book, a copy of the transactions that send coins from or to one of your addresses, accounts, reserve keys, personal settings, and a pointer to the current best block.

(Note: Bitcoin core's "accounts" feature was deprecated some years ago)

> **Comments:**
> **username_3**: New wallets are using SQLite, since the OP mentioned it they probably using that so i doubt a Berkeley DB tool would work for their use case  
> **username_1**: @darosier, AIUI Bitcoin core uses different libraries for the wallet file than for the other files. https://github.com/bitcoin/bitcoin/issues/20160  
> **username_0**: I ran `db_dump` on the already backed up wallet.dat (sqlite) and it did dump some interesting info ie. I the name of the db 'main' and the keys. I guess thats pretty much all there is in the wallet..? Was hoping to see a visual depiction of the db. I haven't marked this answer as correct yet as I still would like to know which password / key the browser is wanting  
> **username_1**: @leo: I'd guess it *needs* the password used to encrypt the key values (if you protected the wallet.dat with a password) But I don't know if Bitcoin Core uses some global encryption provided by the DB library or whether it applies its own encryption to the relevant value contents only (I thought it was the latter but don't actually know for sure). I surmise SQlite might be asking for a global DB password which doesn't apply, might be doing so because it is confused or might be doing so because it wants you to decide if one is needed. I'm not familiar with SQlite  

---

