DBRepair development

Is it possible to get some feedback while running, or an initial estimate on time remaining?

@ChuckPa Running this on Windows 10 with an i7-9700 CPU using the powershell script on auto. I started at about 830pm on Friday. It is now 7:40am on Sunday. The only thing I see in the powershell script is Performing DB cleanup tasks. How do I know if it is still doing its thing or somehow hungup and waiting on me for something? I don’t have a huge amount of media, plenty of hard drive space.

I do see that the file com.plexapp.plugins.library.db-shm is being updated using file explorer.

Thanks for any help. I have been a LONG time user, always ran the beta when available and this is the first issue I have ever had.

2025-06-06 20.36.03 – Session start: Host is Windows 10 (Build 19045)
2025-06-06 20.36.07 – Stop - START
2025-06-06 20.36.20 – Auto - START
2025-06-06 20.36.20 – Performing DB cleanup tasks.

You’ll see the SHM and WAL files being updated.

It’s a real pain.

If you have a backup of the DB, it might be worth Punting this, copying the backup into place, and then letting PMS 1.41.8 do the actual cleanup

If you do switch to a backup database, remember to delete the WAL & SHM files . If you don’t , the can corrupt the backup you just placed there.

1 Like

This is what I ended up doing.

What exactly do you mean by they can corrupt the database? It’s this something that would manifest an error, or would this be a silent corporation?

The reason I ask is because I didn’t delete/remove these two files when I deflated my database a couple of weeks ago.

After I noticed that my server was still becoming unresponsive and generally slower than it normally was, did I find reference to deleting these files.

I deleted them several days ago. PMS is working much faster and I have seen no problems that I can tell.

So, in your opinion, did I dodge a bullet or could they’re be errors in my main database I’m not aware of?

Is this something that would show up but running DBRepair?

The SHM and WAL files are in-process files associated with the DB file currently being used.

When you change the DB (replace it with a backup), the WAL and SHM files are no longer valid. They contain the pending transactions for the old DB.

When you don’t delete them, PMS will use them as if they are part of the currently active .DB. This will result in corruption

Ok, so it’s this only an issue when you use a backup file? I deflated my current database - so this wouldn’t apply to my scenario. :thinking:

How would the corruption reveal itself? Could or be repaired by your tool?

the corruption could be any to all the content (not structure)

Being content, there is nothing my tool could do.

1 Like

I accidentally stopped ImageMaid while it was running. Now if I run it or go to Plex/Troubleshooting/Optimize database it hangs then Plex can’t connect. So I’ve extracted DBRepair (thank you for developing this @ChuckPa), stopped PMS (1), and run auto (2) via SSH in a Linux PC terminal window.

I see in the typical sample sessions the first ā€˜checking’ step takes about 20 seconds. Awesome. In my terminal window ā€˜checking the PMS databases’ has been running for over two hours however, which I’m thinking is a problem..

  • My com.plexapp.plugins.library.db file is 85 GB and the .blobs.db file is 288 MB .
  • My Plex directory is running on an SSD card in a Synology DSM 7
  • SSH CPU is using 0% of resources; SSH/Plex Media Server is using 7 MB of memory and reading at 15 MB p/sec
  • DBRepair log states:
    2025-06-21 15.39.04 - Session start: Host is Synology (DSM 7)
    2025-06-21 15.39.30 - Stop - PASS
    2025-06-21 15.40.47 - Auto - START

Should I exit (99), then skip the ā€˜checking’ step and run repair (5), and should that fail exit again then run ā€˜replace’ (9)? It’s going to stop checking and move onto repair as soon as I click ā€˜reply’, I betcha…

This looks like classic DB Bloat from PMS 1.41.7 . Did you install and use 1.41.7 ?

Probably., I’m on beta and keep it current. I’m now running 1.41.8.9834-…

I see a lot of talk recently about a ā€˜deflate’ command, but can’t see it in the read.me. Is there another version of DBRepair other than latest that includes this? WhaddoIdo?

@adampope

Here is a How-To :see_no_evil_monkey: lol

  1. SSH into the machine
  2. sudo bash
  3. COPY the text of this entire block
#!/bin/bash

[ "$(whoami)" != "root" ] &&  echo You must 'sudo bash' to run this script && exit 1

PSQL="/var/packages/PlexMediaServer/target/Plex SQLite"

cd "/var/packages/PlexMediaServer/shares/PlexMediaServer/AppData/Plex Media Server/Plug-in Support/Databases"
echo ==== Current listing
ls -lah

echo ==== Vacuuming DB
time "$PSQL" com.plexapp.plugins.library.db << EOT
--removed--
EOT

chown PlexMediaServer:PlexMediaServer com.plexapp.plugins.library.db

echo ==== Deflated DB listing
ls -lah com.plexapp.plugins.library.db
  1. PASTE it into the new file
  2. Grant execute permission
  3. As root, run it.

It looks like this

---- Prototype SQL code removed ----

chown PlexMediaServer:PlexMediaServer com.plexapp.plugins.library.db

echo ==== Deflated DB listing
ls -lah com.plexapp.plugins.library.db

bash-4.4# chmod +x Deflate
bash-4.4# ./Deflate
==== Current listing
total 232M
drwx------+ 2 PlexMediaServer PlexMediaServer 4.0K Jun 20 02:03 .
drwx------+ 7 PlexMediaServer PlexMediaServer 4.0K Nov 25 2023 ..
-rwx------+ 1 PlexMediaServer PlexMediaServer 1.1M Jun 19 02:03 com.plexapp.plugins.library.blobs.db
-rwx------+ 1 PlexMediaServer PlexMediaServer 1.1M Jun 11 03:05 com.plexapp.plugins.library.blobs.db-2025-06-11
-rwx------+ 1 PlexMediaServer PlexMediaServer 1.1M Jun 14 03:05 com.plexapp.plugins.library.blobs.db-2025-06-14
-rwx------+ 1 PlexMediaServer PlexMediaServer 1.1M Jun 17 03:05 com.plexapp.plugins.library.blobs.db-2025-06-17
-rwx------+ 1 PlexMediaServer PlexMediaServer 1.1M Jun 20 02:03 com.plexapp.plugins.library.blobs.db-2025-06-20
-rwx------+ 1 PlexMediaServer PlexMediaServer 32K Jun 19 02:03 com.plexapp.plugins.library.blobs.db-shm
-rwx------+ 1 PlexMediaServer PlexMediaServer 4.3M Jun 19 02:03 com.plexapp.plugins.library.blobs.db-wal
-rwx------+ 1 PlexMediaServer PlexMediaServer 38M Jun 21 12:47 com.plexapp.plugins.library.db
-rwx------+ 1 PlexMediaServer PlexMediaServer 36M Jun 11 03:05 com.plexapp.plugins.library.db-2025-06-11
-rwx------+ 1 PlexMediaServer PlexMediaServer 36M Jun 14 03:05 com.plexapp.plugins.library.db-2025-06-14
-rwx------+ 1 PlexMediaServer PlexMediaServer 36M Jun 17 03:05 com.plexapp.plugins.library.db-2025-06-17
-rwx------+ 1 PlexMediaServer PlexMediaServer 38M Jun 20 02:03 com.plexapp.plugins.library.db-2025-06-20
-rwx------+ 1 PlexMediaServer PlexMediaServer 96K Jun 21 14:02 com.plexapp.plugins.library.db-shm
-rwx------+ 1 PlexMediaServer PlexMediaServer 39M Jun 21 14:02 com.plexapp.plugins.library.db-wal
----------+ 1 root root 83K Dec 7 2024 DBRepair.log
==== Vacuuming DB

real 0m3.113s
user 0m0.940s
sys 0m0.850s
==== Deflated DB listing
-rwx------+ 1 PlexMediaServer PlexMediaServer 38M Jun 21 14:02 com.plexapp.plugins.library.db
bash-4.4#


#### On a DS418j,   it took 38 minutes to deflate a 32GB DB.

#### Judge your time accordingly.
1 Like

Thanks for this, and apologies for being a complete numpty. I’m stuck at step 4 - paste it into the new file.

Which new file? Where should it be located? And once added, what command should I be running? cat > deflate? I’m totally confused by the above, so sorry!

To highlight on Linux

  1. Go to top of text to be copied
  2. HOLD left mouse button
  3. Drag down until bottom line / last character highlighted
  4. Let go of mouse
  5. Right-Click COPY

To paste,

  1. On command line, type the cat >Deflate command and hit enter
  2. with cursor in the window RIGHT-CLICK Paste
  3. Hit enter
  4. hit Control+D (to close the file)

On Windows ( I THINK – don’t quote me)

  1. click & hold left mouse to start highlighting
  2. When all selected , hit ENTER
  3. Now go to where you want to paste it — Right-Click (it will paste itself)

You can always use a text editor ( Syno Text Editor works great for this )

Ah, thanks again @ChuckPa. Is there a ā€˜change directory to plex database folder’ step to create the Deflate file in missing there? That’s what I did anyhow, and bashed ../Deflate and pretty quickly caught an error:

==== Current listing
total 425G
drwx------+ 1 PlexMediaServer PlexMediaServer 1.4K Jun 21 19:53 .
drwx------+ 1 PlexMediaServer PlexMediaServer 100 Apr 27 2024 ..
-rwx------+ 1 PlexMediaServer PlexMediaServer 388K Jun 21 18:39 com.plexapp.dlna.db
-rwx------+ 1 PlexMediaServer PlexMediaServer 32K Jun 21 18:39 com.plexapp.dlna.db-shm
-rwx------+ 1 PlexMediaServer PlexMediaServer 741K Jun 21 18:39 com.plexapp.dlna.db-wal
-rw-rw-r-- 1 PlexMediaServer PlexMediaServer 289M Jun 20 04:20 com.plexapp.plugins.library.blobs.db
-rwx------+ 1 PlexMediaServer PlexMediaServer 286M Jun 11 07:07 com.plexapp.plugins.library.blobs.db-2025-06-11
-rwx------+ 1 PlexMediaServer PlexMediaServer 286M Jun 14 07:17 com.plexapp.plugins.library.blobs.db-2025-06-14
-rwx------+ 1 PlexMediaServer PlexMediaServer 289M Jun 17 07:12 com.plexapp.plugins.library.blobs.db-2025-06-17
-rwx------+ 1 PlexMediaServer PlexMediaServer 289M Jun 20 07:11 com.plexapp.plugins.library.blobs.db-2025-06-20
-rw-rw-r-- 1 PlexMediaServer PlexMediaServer 32K Jun 21 18:39 com.plexapp.plugins.library.blobs.db-shm
-rw-rw-r-- 1 PlexMediaServer PlexMediaServer 0 Jun 21 18:39 com.plexapp.plugins.library.blobs.db-wal
-rw-rw-r-- 1 PlexMediaServer PlexMediaServer 85G Jun 21 19:20 com.plexapp.plugins.library.db
-rwx------+ 1 PlexMediaServer PlexMediaServer 85G Jun 11 07:07 com.plexapp.plugins.library.db-2025-06-11
-rwx------+ 1 PlexMediaServer PlexMediaServer 85G Jun 14 07:17 com.plexapp.plugins.library.db-2025-06-14
-rwx------+ 1 PlexMediaServer PlexMediaServer 85G Jun 17 07:12 com.plexapp.plugins.library.db-2025-06-17
-rwx------+ 1 PlexMediaServer PlexMediaServer 85G Jun 20 07:11 com.plexapp.plugins.library.db-2025-06-20
-rw-rw-r-- 1 PlexMediaServer PlexMediaServer 416K Jun 21 19:36 com.plexapp.plugins.library.db-shm
-rw-rw-r-- 1 PlexMediaServer PlexMediaServer 53M Jun 21 19:37 com.plexapp.plugins.library.db-wal
----------+ 1 root root 220 Jun 21 15:40 DBRepair.log
d---------+ 1 root root 0 Jun 21 15:39 dbtmp
—x------ 1 root root 940 Jun 21 19:53 Deflate
drwx------+ 1 PlexMediaServer PlexMediaServer 82 Jun 21 14:07 ā€˜Music Analysis 5’
==== Vacuuming DB
Parse error near line 1: table temp_bandwidth already exists
CREATE TABLE temp_bandwidth as select * from statistics_bandwidth where accoun
^— error here

…so I added DROP TABLE IF EXISTS temp_bandwidth. to the start of the SQL block, and now it… is… running, hooray!

Completed in 70m, reduced database from 85 GB to 404 MB, Optimising now completes in under 1m and no metdata lost. Thanks @ChuckPa amazing stuff…

@adampope

This is the line in the script for DSM 7. :slight_smile:

I use the universal path to the shared folder . I don’t know which physical volume it might actually be on.

Did you use DBRepair to optimize it?

Ah! OK, location of diectory is irrelevant then.

I optimised it via the Plex UI. You think running DBRepair on auto would also help?

After all the records are removed, Vacuum simply compacts. It does not physically reorder / optimize the DB.

This is the principle gain of DBRepair exporting & reimporting the SORTED DB.

1 Like

side question: does automatic also include stop and start?

It doesn’t say it, so I assume not.

It doesn’t, as the command to run it differs across systems I gather

1 Like