<p>It sounds like your wallet.dat file is still intact, but some of the environment data has gotten corrupted (possibly due to moving wallet files).</p>

<p>Try doing</p>

<pre><code>db_load -r lsn wallet.dat
</code></pre>

<p>This will reset the LSNs in the wallet.dat file which should cause the errors in the db.log to go away. Once you do that, delete the <code>database/</code> folder and start Bitcoin Core.</p>

CC BY-SA 4.0
2019-06-14T16:41:53.017Z
This seems to make the wallet load just fine, though I wonder if all keys were erased?  Is this error msg expected? 22019-06-14T16:40:30Z [default wallet] Keys: 0 plaintext, 0 encrypted, 0 w/ metadata, 0 total. Unknown wallet records: 0 ?
Jernej
CC BY-SA 4.0
2019-06-14T18:43:00.680Z
That doesn't sound good. It seems like all of the keys were erased, and that's not supposed to happen. If you do `db_dump` on the file again, do you see what you saw earlier? Do you still see lines beginning with `key`?
Ava Chow
CC BY-SA 4.0
2019-06-14T18:59:55.667Z
Yes I can still see that. As a matter of fact diff seems to be saying that the two dumps are equivalent.
Jernej
CC BY-SA 4.0
2022-02-21T01:42:28.070Z
Don’t use -r lsn you can lose data.
EtherX Dev
CC BY-SA 4.0
2023-02-22T14:18:04.160Z
did that, it worked for me, pywallet sees my addresses now and bitcoin core doesn't crash on import (still scanning, though)
Didi Kohen
CC BY-SA 4.0
2024-03-02T13:51:39.473Z
where would you input the command `db_load -r lsn wallet.dat`?  I tried doing this in the node window console window and I got `Method not found (code -32601)` using `v26.0.0`
Jon Grah
CC BY-SA 4.0
2024-03-02T16:02:55.597Z
trying that command `db_load -r lsn wallet.dat` using `bitcoin-cli.exe` and I get an error:  `error: timeout on transient error: Could not connect to the server 127.0.0.1:8332 (error code 1 - "EOF reached")`  
I don't know if my `wallet.dat` is fully corrupted or just partial.  It is just the `wallet.dat` and I have the encrypted password for the wallet.dat file.  I was able to use a java program and decrypt/dump some keys .  the db.log file showed similar `file unknown has LSN 1/151495, past end of log at 1/28...`  So I assumed i could just load wallet in and get it to work somehow.
Jon Grah
CC BY-SA 4.0
2024-03-02T16:25:33.753Z
@JonGrah `db_load` is an external tool, not one of Bitcoin Core's commands. It comes with BDB and you have to use the terminal or command prompt to use it.
Ava Chow
CC BY-SA 4.0
2019-06-14T14:03:15.677Z
2019-06-14T14:03:15.677Z
Ava Chow
<p>I have a very old wallet.dat that I've put into my .bitcoin folder. When trying to run bitcoind, the service stops giving the following error</p>

<pre><code>2019-06-11T18:14:02Z Using wallet directory /home/nom/.bitcoin
2019-06-11T18:14:02Z init message: Verifying wallet(s)...
2019-06-11T18:14:02Z Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
2019-06-11T18:14:02Z Using wallet wallet.dat
2019-06-11T18:14:02Z BerkeleyEnvironment::Open: LogDir=/home/nom/.bitcoin/database ErrorFile=/home/nom/.bitcoin/db.log
2019-06-11T18:14:02Z Renamed wallet.dat to wallet.dat.1560276842.bak
2019-06-11T18:14:02Z BerkeleyEnvironment::Salvage: Database salvage found errors, all data may not be recoverable.
2019-06-11T18:14:02Z BerkeleyEnvironment::Salvage: WARNING: Unexpected end of file while reading salvage output.
2019-06-11T18:14:02Z Salvage(aggressive) found no records in wallet.dat.1560276842.bak.
2019-06-11T18:14:02Z Error: wallet.dat corrupt, salvage failed
Error: wallet.dat corrupt, salvage failed
2019-06-11T18:14:02Z Shutdown: In progress...
</code></pre>

<p><strong>Edit.</strong> Here is the content of the DB log</p>

<pre><code>file unknown has LSN 1/151495, past end of log at 1/28 Commonly caused by moving a database from one database environment to another without clearing the database LSNs, or by removing all of the log files from a database environment Page 0: metadata page corrupted Page 0: could not check metadata page wallet.dat: DB_VERIFY_BAD: Database verification failed file unknown has LSN 1/151495, past end of log at 1/1080 Commonly caused by moving a database from one database environment to another without clearing the database LSNs, or by removing all of the log files from a database environment wallet.dat.1560341204.bak: DB_VERIFY_BAD: Database verification failed file unknown has LSN 1/151495, past end of log at 1/2500 Commonly caused by moving a database from one database environment to another without clearing the database LSNs, or by removing all of the log files from a database environment wallet.dat.1560341352.bak: DB_VERIFY_BAD: Database verification failed
</code></pre>

<p><strong>Edit.</strong> Using db_dump I am able to see the content of the wallet file ( addresses, keys etc)</p>

<p>Is there any way I could debug this, perhaps recovering just part of the keys or any useful data from the DB itself? Any useful hints how to approach such recovery?</p>

CC BY-SA 4.0
2019-06-13T23:28:18.000Z
Using `db_dump -p <wallet file>`, do you see anything lines that contain `ckey` or `key`? Does the output have `HEADER=END` near the start of the output and `DATA=END` at the end?
Ava Chow
CC BY-SA 4.0
2019-06-14T06:17:11.527Z
Yes, there are plenty of lines with \0key entries and indeed, both HEADER/DATA entries appear. Also if it helps db_verify says the DB is fine. The wallet was created with a fairly old client (2010?)
Jernej
<wallet><wallet-recovery><wallet.dat><database>
Recovery of a corrupted wallet
Jernej
# Recovery of a corrupted wallet

(Asked by: username_0 on 2019-06-11)

I have a very old wallet.dat that I've put into my .bitcoin folder. When trying to run bitcoind, the service stops giving the following error
2019-06-11T18:14:02Z Using wallet directory /home/nom/.bitcoin
2019-06-11T18:14:02Z init message: Verifying wallet(s)...
2019-06-11T18:14:02Z Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
2019-06-11T18:14:02Z Using wallet wallet.dat
2019-06-11T18:14:02Z BerkeleyEnvironment::Open: LogDir=/home/nom/.bitcoin/database ErrorFile=/home/nom/.bitcoin/db.log
2019-06-11T18:14:02Z Renamed wallet.dat to wallet.dat.1560276842.bak
2019-06-11T18:14:02Z BerkeleyEnvironment::Salvage: Database salvage found errors, all data may not be recoverable.
2019-06-11T18:14:02Z BerkeleyEnvironment::Salvage: WARNING: Unexpected end of file while reading salvage output.
2019-06-11T18:14:02Z Salvage(aggressive) found no records in wallet.dat.1560276842.bak.
2019-06-11T18:14:02Z Error: wallet.dat corrupt, salvage failed
Error: wallet.dat corrupt, salvage failed
2019-06-11T18:14:02Z Shutdown: In progress...

Edit. Here is the content of the DB log
file unknown has LSN 1/151495, past end of log at 1/28 Commonly caused by moving a database from one database environment to another without clearing the database LSNs, or by removing all of the log files from a database environment Page 0: metadata page corrupted Page 0: could not check metadata page wallet.dat: DB_VERIFY_BAD: Database verification failed file unknown has LSN 1/151495, past end of log at 1/1080 Commonly caused by moving a database from one database environment to another without clearing the database LSNs, or by removing all of the log files from a database environment wallet.dat.1560341204.bak: DB_VERIFY_BAD: Database verification failed file unknown has LSN 1/151495, past end of log at 1/2500 Commonly caused by moving a database from one database environment to another without clearing the database LSNs, or by removing all of the log files from a database environment wallet.dat.1560341352.bak: DB_VERIFY_BAD: Database verification failed

Edit. Using db_dump I am able to see the content of the wallet file ( addresses, keys etc)
Is there any way I could debug this, perhaps recovering just part of the keys or any useful data from the DB itself? Any useful hints how to approach such recovery?

**Tags:** wallet, wallet-recovery, wallet.dat, database

> **Comments:**
> **username_1**: Using `db_dump -p <wallet file>`, do you see anything lines that contain `ckey` or `key`? Does the output have `HEADER=END` near the start of the output and `DATA=END` at the end?  
> **username_0**: Yes, there are plenty of lines with \0key entries and indeed, both HEADER/DATA entries appear. Also if it helps db_verify says the DB is fine. The wallet was created with a fairly old client (2010?)  

---

## 1 answers

### Answer by username_1 on 2019-06-14. Score: 2

It sounds like your wallet.dat file is still intact, but some of the environment data has gotten corrupted (possibly due to moving wallet files).
Try doing
db_load -r lsn wallet.dat

This will reset the LSNs in the wallet.dat file which should cause the errors in the db.log to go away. Once you do that, delete the database/ folder and start Bitcoin Core.

> **Comments:**
> **username_0**: This seems to make the wallet load just fine, though I wonder if all keys were erased?  Is this error msg expected? 22019-06-14T16:40:30Z [default wallet] Keys: 0 plaintext, 0 encrypted, 0 w/ metadata, 0 total. Unknown wallet records: 0 ?  
> **username_1**: That doesn't sound good. It seems like all of the keys were erased, and that's not supposed to happen. If you do `db_dump` on the file again, do you see what you saw earlier? Do you still see lines beginning with `key`?  
> **username_0**: Yes I can still see that. As a matter of fact diff seems to be saying that the two dumps are equivalent.  
> **username_2**: Don’t use -r lsn you can lose data.  
> **username_3**: did that, it worked for me, pywallet sees my addresses now and bitcoin core doesn't crash on import (still scanning, though)  
> **username_4**: where would you input the command `db_load -r lsn wallet.dat`?  I tried doing this in the node window console window and I got `Method not found (code -32601)` using `v26.0.0`  
> **username_4**: trying that command `db_load -r lsn wallet.dat` using `bitcoin-cli.exe` and I get an error:  `error: timeout on transient error: Could not connect to the server 127.0.0.1:8332 (error code 1 - "EOF reached")`   I don't know if my `wallet.dat` is fully corrupted or just partial.  It is just the `wallet.dat` and I have the encrypted password for the wallet.dat file.  I was able to use a java program and decrypt/dump some keys .  the db.log file showed similar `file unknown has LSN 1/151495, past end of log at 1/28...`  So I assumed i could just load wallet in and get it to work somehow.  
> **username_1**: @JonGrah `db_load` is an external tool, not one of Bitcoin Core's commands. It comes with BDB and you have to use the terminal or command prompt to use it.  

---

