# Check and repair Databases | STORJ Optimization

**URL:** <https://forum.storj.io/t/check-and-repair-databases-storj-optimization/22920>\
**Category:** Node Operators\
**Tags:** database\
**Created:** [June 12, 2023, 11:07am UTC](https://forum.storj.io/t/check-and-repair-databases-storj-optimization/22920 "2023-06-12T11:07:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Walter1](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/walter1/32/7825_2.png) [@Walter1](https://forum.storj.io/u/Walter1)\
**Post date:** [June 12, 2023, 11:07am UTC](https://forum.storj.io/t/check-and-repair-databases-storj-optimization/22920/1 "2023-06-12T11:07:46Z")

</div>

Hello together,

today I discovered some great approach to check quickly all data bases.

First you download sqlite3 as per guide:

> **[How to fix a "database disk image is malformed"](https://support.storj.io/hc/en-us/articles/360029309111-How-to-fix-a-database-disk-image-is-malformed-)**
>
> Problem
> Sometimes a Storage Node Operator may encounter the "database disk image is malformed" error in their log. This could happen during unplanned shutdown or reboot. The error indicates that on...

Then you should download notepad++ and switch the view to automatic line-switching. The reason why we swtich to that line-switching is to keep the overview and not scrolling annoyingly to the right and left because the command line is that long.

![grafik](https://storj-s3.bcdn.literatehosting.net/original/2X/5/5313b6dd4d82e9d280b8e538331304318061cb26.png)

Now you can already start preparing your command to check all 13 data bases with one command:

sqlite3 /mnt/disk-1/STORJ-1/storage/heldamount.db “PRAGMA integrity\_check;”; sqlite3 /mnt/disk-1/STORJ-1/storage/info.db “PRAGMA integrity\_check;”; sqlite3 /mnt/disk-1/STORJ-1/storage/notifications.db “PRAGMA integrity\_check;”  
… and so on till you have all 13.

When executed and the DB’s are looking fine it looks like this:

![grafik](https://storj-s3.bcdn.literatehosting.net/original/2X/f/f7ac80754d9a8d5ad437dc20639f8746917f38bd.png)

When there are errors it looks like this:

![grafik](https://storj-s3.bcdn.literatehosting.net/original/2X/4/470ca2eb27bc63216b3bf3c0aa399613bb8bf812.png)

When you have multiple nodes and want to continue then just change the command with Ctrl + H and then replace all with the next mount point plus the next node number.

Hope this helps and thanks and kind regards,

---

<div class="post-metadata">

**Author:** ![nerdatwork](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/nerdatwork/32/1135_2.png) [@nerdatwork](https://forum.storj.io/u/nerdatwork)\
**Post date:** [June 12, 2023, 11:27am UTC](https://forum.storj.io/t/check-and-repair-databases-storj-optimization/22920/2 "2023-06-12T11:27:02Z")

</div>

> [@Walter1](#):
>
> sqlite3 /mnt/disk-1/STORJ-1/storage/heldamount.db “PRAGMA integrity\_check;”; sqlite3 /mnt/disk-1/STORJ-1/storage/info.db “PRAGMA integrity\_check;”; sqlite3 /mnt/disk-1/STORJ-1/storage/notifications.db “PRAGMA integrity\_check;”  
> … and so on till you have all 13.

This can already be achieved with a shorter simpler version as shown in documentation

Linux:

> find /path/to/storage/ -iname “\*.db” -maxdepth 1 -print0 -exec sqlite3 ‘{}’ ‘PRAGMA integrity\_check;’ ‘;’

Windows:

> Get-ChildItem X:\storagenode\storage\*.db -File | %{$_.Name + " " + $(sqlite3.exe $_.FullName “PRAGMA integrity\_check;”)}

This is without the need to mention all the dbs by name or the need to have notepad++

**I think you totally missed point 5.2.5 from the documentation.**

---

<div class="post-metadata">

**Author:** ![Walter1](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/walter1/32/7825_2.png) [@Walter1](https://forum.storj.io/u/Walter1)\
**Post date:** [June 12, 2023, 11:34am UTC](https://forum.storj.io/t/check-and-repair-databases-storj-optimization/22920/3 "2023-06-12T11:34:33Z")

</div>

With this command I’m getting the message: find: warning: you have specified the global option -maxdepth after the argument -iname, but global options are not positional, i.e., -maxdepth affects tests specified before it as well as those specified after it. Please specify global options before other arguments.

Also when I try to fix the DB I’m getting the following error message with this command:

docker run -it --rm --mount type=tmpfs,destination=/ramdisk,tmpfs-size=1.5G --mount type=bind,src=Y:/mnt/disk-1/STORJ-1/storage,dst=/data sstc/sqlite3 sh

Error message:

docker: Error response from daemon: invalid mount config for type “bind”: invalid mount path: ‘Y:…’ mount path must be absolute.

Update:

Unfortunately I can’t just delete the corrupted DB and then restart with a new. It has to be repaired. Does anyone know how to repair the piece\_expiration.db?

---

<div class="post-metadata">

**Author:** ![Stob](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/stob/32/1137_2.png) [@Stob](https://forum.storj.io/u/Stob)\
**Post date:** [June 12, 2023, 12:39pm UTC](https://forum.storj.io/t/check-and-repair-databases-storj-optimization/22920/4 "2023-06-12T12:39:49Z")

</div>

> [@Walter1](#):
>
> how to repair the piece\_expiration.db?

[https://support.storj.io/hc/en-us/articles/360029309111](https://support.storj.io/hc/en-us/articles/360029309111)

Start from step 6 for repairing a database … “We will unload all uncorrupted data and then load it back.”

* * *

> [@Walter1](#):
>
> Unfortunately I can’t just delete the corrupted DB and then restart with a new.

This should totally be possible. A node can start with completely new databases as long as the data and identity is still the same and not corrupt.

[https://support.storj.io/hc/en-us/articles/4403032417044](https://support.storj.io/hc/en-us/articles/4403032417044)

---

<div class="post-metadata">

**Author:** ![Walter1](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/walter1/32/7825_2.png) [@Walter1](https://forum.storj.io/u/Walter1)\
**Post date:** [June 12, 2023, 12:56pm UTC](https://forum.storj.io/t/check-and-repair-databases-storj-optimization/22920/5 "2023-06-12T12:56:15Z")

</div>

I got it run for the first piece\_expiration.db now.

Was struggeling with the docker command, which I don’t need at all with sqlite3 installed and with all the /storage/-paths who have all to be adjusted.

Hope it works soon.

Update:

Perfect it worked for piece\_expiration.db and for storage\_usage.db and the node is running fine now. The guide should still have more hints, that the commands should be adjusted and not just copied over.

---

<div class="post-metadata">

**Author:** ![Alexey](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/alexey/32/41_2.png) [@Alexey](https://forum.storj.io/u/Alexey)\
**Post date:** [June 13, 2023, 4:25am UTC](https://forum.storj.io/t/check-and-repair-databases-storj-optimization/22920/6 "2023-06-13T04:25:58Z")

</div>

> [@Walter1](#):
>
> With this command I’m getting the message: find: warning: you have specified the global option -maxdepth after the argument -iname, but global options are not positional, i.e., -maxdepth affects tests specified before it as well as those specified after it. Please specify global options before other arguments.

this is simple a warning, but I would fix it.

```auto
find /path/to/storage/ -maxdepth 1 -iname "*.db" -print0 -exec sqlite3 '{}' 'PRAGMA integrity_check;' ';'

```

> [@Walter1](#):
>
> docker run -it --rm --mount type=tmpfs,destination=/ramdisk,tmpfs-size=1.5G --mount type=bind,src=Y:/mnt/disk-1/STORJ-1/storage,dst=/data sstc/sqlite3 sh
> 
> Error message:
> 
> docker: Error response from daemon: invalid mount config for type “bind”: invalid mount path: ‘Y:…’ mount path must be absolute.

You may try it like this:

```auto
docker run -it --rm --mount type=tmpfs,destination=/ramdisk,tmpfs-size=1.5G --mount type=bind,src=Y:\mnt\disk-1\STORJ-1\storage,dst=/data sstc/sqlite3 sh

```

However, it’s for a Windows OS. And are you sure that it’s really have this path?  
In PowerShell:

```auto
ls Y:\mnt\disk-1\STORJ-1\storage

```
