DBRepair development

Done! Worked a charm, took 5m, reducing main DB size by another 5%…

2025-06-22 11.05.05 - Session start: Host is Synology (DSM 7)
2025-06-22 11.05.17 - Stop - PASS
2025-06-22 11.05.24 - Auto - START
2025-06-22 11.05.37 - Check - Check com.plexapp.plugins.library.db - PASS
2025-06-22 11.05.44 - Check - Check com.plexapp.plugins.library.blobs.db - PASS
2025-06-22 11.05.44 - Check - PASS
2025-06-22 11.06.57 - Repair - Export databases - PASS
2025-06-22 11.07.47 - Repair - Import - PASS
2025-06-22 11.07.55 - Repair - Verify main database - PASS (Size: 404MB/379MB).
2025-06-22 11.07.56 - Repair - Verify blobs database - PASS (Size: 288MB/311MB).
2025-06-22 11.07.56 - Repair - Making repaired databases active
2025-06-22 11.07.56 - Repair - Move files - PASS
2025-06-22 11.07.56 - Repair - PASS
2025-06-22 11.07.56 - Repair - PASS
2025-06-22 11.07.56 - Reindex - MakeBackup com.plexapp.plugins.library.db - PASS
2025-06-22 11.07.57 - Reindex - MakeBackup com.plexapp.plugins.library.blobs.db - PASS
2025-06-22 11.07.57 - Reindex - MakeBackup - PASS
2025-06-22 11.08.08 - Reindex - Reindex: com.plexapp.plugins.library.db - PASS
2025-06-22 11.08.09 - Reindex - Reindex: com.plexapp.plugins.library.blobs.db - PASS
2025-06-22 11.08.09 - Reindex - PASS
2025-06-22 11.08.09 - Reindex - PASS
2025-06-22 11.08.09 - Auto - COMPLETED
2025-06-22 11.08.34 - Start - PASS
2025-06-22 11.09.45 - Exit - Delete temp files.
2025-06-22 11.09.46 - Session end. Sun Jun 22 11:09:46 AM IST 2025
2025-06-22 11.09.46 - ============================================================

Start / Stop are a separate mechanism.

A user might want to auto repair then include (merge) watch history.
“Auto” isn’t at the sophistication (automation) level I want.

It was created with the plan to have a DBRepair.conf (config) file.
None of that ever worked as intended but by that time, the popularity mandated I keep the commands as they were.

1 Like

@ChuckPa
Not that I need the script now but maybe you should add another information to the tutorial on GitHub. :wink:

On the bottom of the tutorial by the chapter
DSM 7 - Step 2 - Run DBRepair as the designated username you write:
make sure it is executable.

I think it could be helpful to add a short tutorial how you make it executable (what steps would be necessary here) and/or how to check if it is. (I personally would have no clue how to do this) :rofl:

The examples for the different environments show the command to do it.

In all cases on Unix & Linux hosts, as I show the commands.
Granted it takes a few extra steps if you are afraid of using SSH / Putty into the Syno.

The general form is always:

    sudo bash         <----  Elevate to administrator (root) privilege) 
    cd /path/to/DBRepair.tar_dir  <---- change to directory where DBRepair.tar is
    tar xf DBRepair-x.y.z.tar.gz  <---- Extract the tar file to get all the pieces out
    cd DBRepair-x.y.z             <--- Get into the subdirectory where DBRepair.sh is
    chmod +x DBRepair.sh          <--- Give it execute permission
    ./DBRepair.sh stop auto start exit   <--- Run it
1 Like

Got it!
Sorry, I was a bit confused first because I thought “executable” has something to do with the file permission checkboxes on DSM. But this make sense now. :slight_smile:

Thanks a lot guys for clarifying this!

1 Like

Hi.

For some reason, prune isn’t working for me.

The script is located in volume1, PlexMediaServer on volume2.

The prune command doesn’t see the files.

DSM 7.2.2-72806 Update 4

Does it find the database files OK when you run auto, check, etc.?

Does it say “No files found to prune”?

That just means there were no files older than 30 days.

If it said something else, please copy the output to the thread.


Example: From my DS918+:

Enter command # -or- command name (4 char min) : prune

Counting how many files can be removed.
No files found to prune.

And from the log file (I ran prune twice):

2025-08-14 15.37.27 - ============================================================
2025-08-14 15.37.27 - Session start: Host is Synology (DSM 7)
2025-08-14 15.37.36 - Stop    - PASS
2025-08-14 15.37.38 - Prune   - START
2025-08-14 15.37.40 - Prune   - PASS
2025-08-14 15.47.26 - Prune   - START
2025-08-14 15.47.28 - Prune   - PASS
==================================================================================

Everything is fine with the database.

The files were not deleted because they are less than 30 days old.

Thank you for your help.

See the README.md

Environment Variables

DBRepair now supports the use of environment variables to allow customization of some operations.

WARNING: Use of these variables may adverse impact PMS operation or performance. USE WITH CAUTION.

DBREPAIR_CACHEAGE - Specify the maximum age for PhotoTrancoder Cache images to be retained
Default DBREPAIR_CACHEAGE is set at 30 days.

You may override this by setting DBREPAIR_CACHEAGE=N, where N is the number of days worth of cache image you wish to retain.

When using interactively, DBRepair will prompt you to confirm OK to remove and show you the cache age

Example: export DBREPAIR_CACHEAGE=20

Enter command # -or- command name (4 char min) : remove

Counting how many files are more than 20 days old.
OK to prune 4497 files?  (Y/N) ?
3 Likes

Hi.

Is it possible to attach https://textual.textualize.io/ to DBRepair so that you don’t have to log in via SSH?

@ClassicUA

That would unfortunately be a no.

The script runs native on the target host with no other dependencies other than an installed Plex server (Plex SQLite)

Adding dependencies violates the design premise

If you’re familiar with SSH:

  1. ssh-copy-id username@hostname
  2. ssh user@hostname sudo /path/to/dbrepair.sh stop auto start exit

No interactive login required
You will need to add ‘user’ to the /etc/sudoers

ALL:

Due to recent events, I’ve had to dust off some other code and tweak it a bit.

Might I impose and ask for some QA help to confirm it works as expected on the various hosts and docker containers?

v1.11.0

UserCredentialReset.tar (30 KB)

1 Like

Works fine on my N100/Ubuntu 24.04 box.
I used Settings → server_name → General + Remove to remove the server from my account.
I then ran the script and it reclaimed the server.

User Credential Reset output
$ sudo ./UserCredentialReset.sh claim-JJ7HzpzsNZgadY4Mxu9-

          User credential reset & reclaim tool for Plex Media Server (Linux)  (Ubuntu 24.04.3 LTS)
                                     (Version: v1.11.0)

This utility will reset the server's credentials.
It will next reclaim the server for you using a Plex Claim token you provide from https://plex.tv/claim

Using given claim token:  'claim-JJ7HzpzsNZgadY4Mxu9-'

Stopping PMS
Clearing Preferences.xml
Getting new credentials from Plex.tv
Claim completed without errors.
 Username: FordGuy61
 Email:    <redacted>

Starting PMS
Complete.
$

THank you.

I did find a bug (typo) — fixed it.

UserCredentialReset is now published v1.11.0

1 Like

I took a look at UserCredentialReset.sh

Although the README mentions MacOS might have been supported through manual location of the Preferences.xml file, it won’t work for a modern MacOS which has too many unique behaviors, different command arguments for stat and sed, and no Preferences.xml like we have on Linux.

It looks like PMS stores its config for MacOS in
com.plexapp.plexmediaserver.plist
that’s no longer human readable.
The user has to modify it using the Defaults(1) command.

I found a GUI client works well for resetting as described in the Plex Support docs, but I wanted to say nice job on the shell utility. It was a pleasure to read, and have a nice weekend :slight_smile:

I’ll make certain to remove MacOS. It runs as your username.

AFAIK, no claiming is required

Folks,

Since “DeflateGate” is still lingering…
and I’ve learned what’s needed for bandwidth_statistics to continue to function,

I’ve prototyped DBRepair v1.12.00

The text it current outputs feels “off”
(Auto & Deflate should, imho, be mostly similar as they are 3-step processes)

I need help with how to fix the working. May I ask your input please ?

 21 - 'prune'     - Remove old image files (jpeg,jpg,png) from PhotoTranscoder cache & all temp files left by PMS.
 22 - 'purge'     - Remove unused temp files.
 23 - 'deflate'   - Deflate a bloated PMS main database.
 42 - 'ignore'    - Ignore duplicate/constraint errors.

 88 - 'update'    - Check for updates.
 98 - 'quit'      - Quit immediately.  Keep all temporary files.
 99 - 'exit'      - Exit with cleanup options.

Enter command # -or- command name (4 char min) : 23
 
Automatic Check and Deflate started.

Checking the PMS databases

Check complete.  PMS main database is OK.
Check complete.  PMS blobs database is OK.

Backup current databases with '-BACKUP-2025-10-04_02.15.41' timestamp.
Starting Deflate.  (There will be no output until complete.)
PMS main database successfully repaired.
Reducing main database size.
PMS main database size reduced.
Verifying PMS main database.
Verification complete.  PMS main database is OK.  New size = 206 MB
PMS main database deflate completed.
Saving current main database with '-BLOATED-2025-10-04_02.15.41'
Making deflated database active
Deflate complete. Please check your library settings and contents for completeness.
Deflate successful.
Recommend running Auto next to complete optimization of new database.

Select

  1 - 'stop'      - (Not available. Stop manually.)
  2 - 'automatic' - Check, Repair/Optimize, and Reindex Database in one step.

This example did a full check of a 31 GB DB, and reduced it in 12 minutes.

1 Like

You might leave out the Automatic part, e.g.

Deflate started.

Checking the PMS database

I’d be interested to know the starting DB size,
the ending DB size, and the percentage reduction, e.g.

PMS main database size reduced from 10 GB to 206 MB (98%).

Then Automatic would continue to mean the same thing people are used to.
Thanks for working on it.

1 Like

@nibbles

Regarding shell math.

  1. I’ve flipped it around. Every test I ran was a “99%” reduction which was useless.
  2. Simple multiplier seems to work better
[chuck@lizum databases.2025.05.17.2037]$ SizeStart=135000
[chuck@lizum databases.2025.05.17.2038]$ SizeFinish=207
[chuck@lizum databases.2025.05.17.2039]$ SizeReduce=$(($SizeStart / $SizeFinish))
[chuck@lizum databases.2025.05.17.2040]$ echo  Start=$SizeStart MB, Finish=$SizeFinish MB, Reduction=$SizeReduce \%
Start=135000 MB, Finish=207 MB, Reduction=652 %
[chuck@lizum databases.2025.05.17.2041]$

This ratio expresses multiples of the Finish size needed to get to Start size.

Does this work better?


I’m fixing the comments throughout the new function. Almost there.

2 Likes