DBRepair development

@hotif

A few questions

  1. Would you please run these two registry queries for me?
reg query "HKLM\Software\Plex, Inc.\Plex Media Server" /v InstallFolder
reg query "HKCU\Software\Plex, Inc.\Plex Media Server" /v LocalAppDataPath

DBRepair looks in LocalAppDataPath (HKCU)

If it’s missing, it falls back to %USERPROFILE%\AppData\Local\Plex Media Server then ...\Roaming\Plex Media Server

  1. May I see a dir /a of the Databases directory ?

  2. Confirming you “Run as administrator” ? ( I don’t see any errors in the output at this part of startup but might be an omission)

note: action item for me is to extend log creation down into that lowest level
(I overlooked a “WriteLog()” call.)

No problems running or errors during the operation, but one question:

Is it intentional that it locks itself to plex media server.exe? In other words, on W10 it’s impossible to delete the folder / dbrepair.exe unless one stops plex from running. (I discovered this because I still had 0.1999.06 still sitting on my desktop and it was locked to PMS). Surely if one has exited dbrepair it should no longer be in control of plex media server.exe as it shouldn’t be running in the background, no?

PS C:\Users\tobia\AppData\Local\Plex Media Server\Plug-in Support\Databases> reg query "HKLM\Software\Plex, Inc.\Plex Media Server" /v InstallFolder

HKEY_LOCAL_MACHINE\Software\Plex, Inc.\Plex Media Server
    InstallFolder    REG_SZ    C:\Program Files\Plex\Plex Media Server

PS C:\Users\tobia\AppData\Local\Plex Media Server\Plug-in Support\Databases> reg query "HKCU\Software\Plex, Inc.\Plex Media Server" /v LocalAppDataPath


FEHLER: Der angegebene Registrierungsschlüssel bzw. Wert wurde nicht gefunden.

First key is found, second is not available

My installation is an old but standard installation. Data folder is found where the Plex support article points to: Where is the Plex Media Server data directory located? | Plex Support

%USERPROFILE%\AppData\Local\Plex Media Server is the correct path

Wow, that’s one big bloated database

Try this:

Exit/Stop PMS

Then in file-explore, wait for all *.db-wal files and all *.db-shm files to be gone

Wait for at least 10 min.

When they are gone, you should be able to run the DBRepair tool

@hotif

Thank you for this. Please stand by a bit while I get into it.

I want to double check what I’ve done here.

It’s not bloated but almost 13 years old and has tons of data :smiley:

Usually I’m running a slightly modified version of DBRepair-Windows.bat but I’d like to try the new tool.

Sorry, but strongly suspect it is!

The pure size of both it and it’s wal file are extremely big, despite the amount of media you have

@hottif

That’s live data ? WOW! Congrats to you!

I think I have the answer to this too.

If I make an adjustment here, may I send you a test file ?

We will see what’s bloat and what isn’t after we see the test results.

I know, I’m a crazy collector :rofl:
Maybe the new tooll can reduce size and make it a little faster.
The .bat version that I’m running once a week or so produces almost the same size as the input file.

@ChuckPa I’d love to help you test the new version.

The .bat file only handles the physical file structure.

It does not do much for the contents.

This new program (binary) gets down into the DB deep (once it can get the DBs to open) – which is your issue

@hotif

I’m making a few test adjustments here for you now to confirm / disprove what I think we’re seeing.

With your permission, I will send you a download link via PM when ready ?

Sure, I’m ready

@hottif

Please check your PM.

Messages waiting.

Ran through some common tasks on my QNAP via SSH with the new binary. Just a couple minor hiccups and notes.

I miss the AUTO option. It was nice to have a single command to run the check, repair, reindex as like a “default” action.
I ran all the commands except REVERT and IGNORE. They all worked as expected except what I’ve noted below.

STOP and START didn’t work for me. It does work in the previous DBRepair version.

After running stop:

After running start after stopping manually via QNAP GUI:


Sometimes start\stop commands on QNAP get funny outside of the GUI so I’m not surprised this might be a QNAP specific hiccup or permissions thing.

The “EXPUNGE” command didn’t quite do as I had hoped.

It looks like “dead user account records” is about users who no longer have a Plex account rather than user accounts that are no longer connected to my server. Is that correct? If so that is just my own missed expectation.

I have a number of users I removed from my server over the years and their watch history still remains (not a huge deal - just stale unnecessary data), and now their names show up in the mobile server dashboard for “filter by user” and that’s kinda annoying as they aren’t users anymore. They don’t show up when I use the WebGUI dashboard “filter by user”. I had assumed when removing users from my server I was also removing their data, but that wasn’t an accurate assumption on my part. I had hoped the expunge was a timely addition to the tool to help clean that up when the new server dashboard exposed that data was still there. Maybe it’ll at least be hidden like it is in WebGUI in future app updates.

While I’m mentioning that dashboard - and not anything you can do but maybe others who can will see it here - I’d love to have the “everyone\others\me” filter option in the dashboard like Plex Dash had it. That was really useful.

Lastly, the SHOW command for the logfile didn’t work - or the logfile itself isn’t working. Or rather the command opens the logfile, but it showed only logs of the previous version sessions but not the new version sessions. I see a few notes in this topic that logfile might need some additional tweaking though so maybe that’s part of it.

Otherwise, everything else seemed to work just fine for me and did seem snappier than the previous version. I also liked the output\reporting in this version better. It feels cleaner and more “regular user” friendly if that makes sense?

I do think what you have on the GitHub site for “how to” is pretty complete honestly so I think just some updating\refresh of what’s there is probably plenty for a user manual. I particularly like you have a sample session there.

Let me know if there’s anything else I can check. Appreciate it!

@Insomnic_1

Thanks for kicking the tires hard on this:

  1. The “Auto” command is coming. I needed to get all the supporting functions working first else auto would be useless.
    In its new form, you’ll only need “DBRepair auto exit” .. and the ‘exit’ on command line is optional too:
    Automatic will be:
    – Save current stat of PMS
    – If running, STOP PMS
    – Check Databases and get detailed status
    – Run specific task(s) needed
    – Check Saved state of PMS. Restart if was previously running.

  2. Expunge - Yes, this is basic initial cut of it.

    So the watch history is the next thing (if possible) to remove as part of expunge ? (I don’t know what’s in Plex’s cloud-sync versus what’s in the DB)
    I will look and grab it out of there if possible.
    I don’t know if there’s a way for me to see if a user has or doesn’t have access

  • don’t know about the WebGui anymore.
    I don’t have access to Plex internally. (I don’t have any of the old logins)
  1. Show command - DARN IT.
    That’s a clue as to what’s going on.
    Please start it up and type ‘config’ (it will print out the entire configuration as it sees it)
  • On my QNAP, I get:
Enter command # -or- command name (4 char min) : show

Displaying Session Log: /share/CACHEDEV1_DATA/.qpkg/PlexMediaServer/Library/Plex Media Server/Plug-in Support/Databases/DBRepair.log
------------------------------------------------------------
2023-08-29 00.57.58 - PMS running. Could not continue.
2023-08-29 00.59.27 - ============================================================
2023-08-29 00.59.27 - Session start: Host is QNAP
2023-08-29 01.03.41 - ============================================================
2023-08-29 01.03.41 - Session start: Host is QNAP
2024-03-24 12.34.14 - ============================================================
2024-03-24 12.34.14 - Session start: Host is QNAP
2024-03-24 12.35.23 - ============================================================
2024-03-24 12.35.23 - Session start: Host is QNAP
2024-03-24 12.35.29 - Stop    - PASS
2024-03-24 12.35.29 - Auto    - START
  1. Start/Stop control
  • Line 349 of Plex.sh is where it’s using the QNAP function I wrote to stop PMS (what App Center uses)
    Not sure why you’re having issue with it.
[/share/Public] # ./DBRepair



            Database Repair Utility for Plex Media Server  (QNAP)
                       Version 0.1999.08 (Aug 31 2026)


Select

  1 - 'stop'      - Stop PMS.
  3 - 'check'     - Perform integrity check of database and FTS indexes.
  4 - 'vacuum'    - Remove empty space from database without optimizing.
  5 - 'repair'    - Repair/Optimize databases.
  6 - 'reindex'   - Rebuild database indexes.
  7 - 'start'     - Start PMS

 10 - 'show'      - Show logfile.
 11 - 'status'    - Report status of PMS (run-state and databases).
 12 - 'history'   - Show command history of this session.
 13 - 'revert'    - Revert DBs to immediately before history index.

 21 - 'prune'     - Remove old image files from PhotoTranscoder cache & all temp files left by PMS.
 22 - 'expunge'   - Remove view history from non-existent user accounts
 23 - 'deflate'   - Deflate a bloated PMS main database.
 42 - 'ignore'    - Ignore duplicate/constraint errors.

 98 - 'quit'      - Quit immediately.  Keep all temporary files.
 99 - 'exit'      - Exit with cleanup options.

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


Status report: Mon Aug 31 15:02:29 2026
  PMS is stopped.
  Databases are not checked, Status unknown.
  FTS indexes are not checked, Status unknown.


Select

  1 - 'stop'      - Stop PMS.
  3 - 'check'     - Perform integrity check of database and FTS indexes.
  4 - 'vacuum'    - Remove empty space from database without optimizing.
  5 - 'repair'    - Repair/Optimize databases.
  6 - 'reindex'   - Rebuild database indexes.
  7 - 'start'     - Start PMS

 10 - 'show'      - Show logfile.
 11 - 'status'    - Report status of PMS (run-state and databases).
 12 - 'history'   - Show command history of this session.
 13 - 'revert'    - Revert DBs to immediately before history index.

 21 - 'prune'     - Remove old image files from PhotoTranscoder cache & all temp files left by PMS.
 22 - 'expunge'   - Remove view history from non-existent user accounts
 23 - 'deflate'   - Deflate a bloated PMS main database.
 42 - 'ignore'    - Ignore duplicate/constraint errors.

 98 - 'quit'      - Quit immediately.  Keep all temporary files.
 99 - 'exit'      - Exit with cleanup options.

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

Starting PMS.
Starting Plex Media Server...
Started PMS.

Select

  1 - 'stop'      - Stop PMS.
  3 - 'check'     - Perform integrity check of database and FTS indexes.
  4 - 'vacuum'    - Remove empty space from database without optimizing.
  5 - 'repair'    - Repair/Optimize databases.
  6 - 'reindex'   - Rebuild database indexes.
  7 - 'start'     - Start PMS

 10 - 'show'      - Show logfile.
 11 - 'status'    - Report status of PMS (run-state and databases).
 12 - 'history'   - Show command history of this session.
 13 - 'revert'    - Revert DBs to immediately before history index.

 21 - 'prune'     - Remove old image files from PhotoTranscoder cache & all temp files left by PMS.
 22 - 'expunge'   - Remove view history from non-existent user accounts
 23 - 'deflate'   - Deflate a bloated PMS main database.
 42 - 'ignore'    - Ignore duplicate/constraint errors.

 98 - 'quit'      - Quit immediately.  Keep all temporary files.
 99 - 'exit'      - Exit with cleanup options.

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


Status report: Mon Aug 31 15:02:36 2026
  PMS is running.
  Databases are not checked, Status unknown.
  FTS indexes are not checked, Status unknown.


Select

  1 - 'stop'      - Stop PMS.
  3 - 'check'     - Perform integrity check of database and FTS indexes.
  4 - 'vacuum'    - Remove empty space from database without optimizing.
  5 - 'repair'    - Repair/Optimize databases.
  6 - 'reindex'   - Rebuild database indexes.
  7 - 'start'     - Start PMS

 10 - 'show'      - Show logfile.
 11 - 'status'    - Report status of PMS (run-state and databases).
 12 - 'history'   - Show command history of this session.
 13 - 'revert'    - Revert DBs to immediately before history index.

 21 - 'prune'     - Remove old image files from PhotoTranscoder cache & all temp files left by PMS.
 22 - 'expunge'   - Remove view history from non-existent user accounts
 23 - 'deflate'   - Deflate a bloated PMS main database.
 42 - 'ignore'    - Ignore duplicate/constraint errors.

 98 - 'quit'      - Quit immediately.  Keep all temporary files.
 99 - 'exit'      - Exit with cleanup options.

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

Stopping PMS. (60 second max delay)
Stopping Plex Media Server...
      
Stopped PMS.

Select

  1 - 'stop'      - Stop PMS.
  3 - 'check'     - Perform integrity check of database and FTS indexes.
  4 - 'vacuum'    - Remove empty space from database without optimizing.
  5 - 'repair'    - Repair/Optimize databases.
  6 - 'reindex'   - Rebuild database indexes.
  7 - 'start'     - Start PMS

 10 - 'show'      - Show logfile.
 11 - 'status'    - Report status of PMS (run-state and databases).
 12 - 'history'   - Show command history of this session.
 13 - 'revert'    - Revert DBs to immediately before history index.

 21 - 'prune'     - Remove old image files from PhotoTranscoder cache & all temp files left by PMS.
 22 - 'expunge'   - Remove view history from non-existent user accounts
 23 - 'deflate'   - Deflate a bloated PMS main database.
 42 - 'ignore'    - Ignore duplicate/constraint errors.

 98 - 'quit'      - Quit immediately.  Keep all temporary files.
 99 - 'exit'      - Exit with cleanup options.

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

Starting PMS.
Starting Plex Media Server...
Started PMS.

Select

  1 - 'stop'      - Stop PMS.
  3 - 'check'     - Perform integrity check of database and FTS indexes.
  4 - 'vacuum'    - Remove empty space from database without optimizing.
  5 - 'repair'    - Repair/Optimize databases.
  6 - 'reindex'   - Rebuild database indexes.
  7 - 'start'     - Start PMS

 10 - 'show'      - Show logfile.
 11 - 'status'    - Report status of PMS (run-state and databases).
 12 - 'history'   - Show command history of this session.
 13 - 'revert'    - Revert DBs to immediately before history index.

 21 - 'prune'     - Remove old image files from PhotoTranscoder cache & all temp files left by PMS.
 22 - 'expunge'   - Remove view history from non-existent user accounts
 23 - 'deflate'   - Deflate a bloated PMS main database.
 42 - 'ignore'    - Ignore duplicate/constraint errors.

 98 - 'quit'      - Quit immediately.  Keep all temporary files.
 99 - 'exit'      - Exit with cleanup options.

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


Status report: Mon Aug 31 15:02:59 2026
  PMS is running.
  Databases are not checked, Status unknown.
  FTS indexes are not checked, Status unknown.


Select

  1 - 'stop'      - Stop PMS.
  3 - 'check'     - Perform integrity check of database and FTS indexes.
  4 - 'vacuum'    - Remove empty space from database without optimizing.
  5 - 'repair'    - Repair/Optimize databases.
  6 - 'reindex'   - Rebuild database indexes.
  7 - 'start'     - Start PMS

 10 - 'show'      - Show logfile.
 11 - 'status'    - Report status of PMS (run-state and databases).
 12 - 'history'   - Show command history of this session.
 13 - 'revert'    - Revert DBs to immediately before history index.

 21 - 'prune'     - Remove old image files from PhotoTranscoder cache & all temp files left by PMS.
 22 - 'expunge'   - Remove view history from non-existent user accounts
 23 - 'deflate'   - Deflate a bloated PMS main database.
 42 - 'ignore'    - Ignore duplicate/constraint errors.

 98 - 'quit'      - Quit immediately.  Keep all temporary files.
 99 - 'exit'      - Exit with cleanup options.

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

I ran the latest Linux build and received this message when doing the repair command:

-– Processing Main DB —
Rebuilding Main DB
Transferring schema.
Building FTS tables.
Generating triggers.
Transferring data records.
Generating indexes.
Populating FTS tables.
Warning: Main DB: 1 track/album/episode row(s) missing parent context.
There is a small issue with the DB. Functionality is not impaired but should be
addressed by PMS as soon as convenient. In each section, listed below, do a
‘Scan Files’ and ‘Refresh All Metadata’. PMS will make the repair.

Library ‘(unknown)’: 1 item(s)

Checking Main DB after rebuild.

Main DB rebuild and verification complete.

-– Processing Blobs DB —
Rebuilding Blobs DB
Transferring schema.
Building FTS tables.
Generating triggers.
Transferring data records.
Generating indexes.
Populating FTS tables.

Checking Blobs DB after rebuild.

Blobs DB rebuild and verification complete.
Making DB(s) active
Swap complete. Live databases updated.

@ChuckPa

  1. Glad it’ll be back and that logic makes total sense. :slight_smile:
  2. It’s a minor annoyance to have stale data in the DB but really I think my issue is probably more of an app\dashboard thing - it should ignore user accounts that aren’t actually active\enabled on the server. The WebGUI dashboard and Plex Dash ignores them, the mobile app should too. A cleanup would be nice, but functionally, it’s not a big deal.
  3. I wasn’t running dbrepair under sudo … when I run it using sudo the log file gets written and SHOW shows recent activity accurately.
  4. Same… I wasn’t running dbrepair under sudo. When I use sudo it stops and starts correctly.

I didn’t typically run dbrepair under sudo previously but when you mentioned not having a problem I guessed it might be permissions thing and ran with sudo. This might simply be user error on my part as I don’t play in terminal that much anymore and my memory sucks for command line if I’m not doing it regularly. :slight_smile:

In case it helps I ran config (under sudo):

--- [ DBRepair: Host Configuration Dump ] ---

  Version:            [0.1999.08]
  Os                  [0]
  Uid / Gid           [0:0]
  Username            [admin]
  Home Directory:     [/share/homes/admin]
  Host Type:          [QNAP]
  Distro Name:        []
  Time Stamp:         [2026-08-31_14-22-15-351]
  Last User:          [None]
  Last Run:           [Never]

  Manual Config:      No
  Root Required:      No
  Scripted Mode:      No
  Ignore Errors:      No
  Remove Duplicates:  No
  Fail Status:        No
  Global Damaged:     No
  Suppr FTS Malform:  No
  Commit Changes:     Yes
 
  --- Main Database ---
  Path:               [/share/CACHEDEV1_DATA/.qpkg/PlexMediaServer/Library/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db]
  Checked:            Yes
  Damaged:            No
  Checked FTS:        Yes
  FTS Damaged:        No
  Bloated:            No
  Fragmented:         No
 
  --- Blobs Database ---
  Path:               [/share/CACHEDEV1_DATA/.qpkg/PlexMediaServer/Library/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.blobs.db]
  Checked:            Yes
  Damaged:            No
  Checked FTS:        Yes
  FTS Damaged:        No
  Bloated:            No
  Fragmented:         No
 
  Owner UID/GID:      1000:100
  Default Perms:      0644
  Stat Format:        [-c]
  Stat Bytes:         [%s]
  Stat Perms:         [%a]
 
  Package Dir:        [/share/CACHEDEV1_DATA/.qpkg/PlexMediaServer]
  SQLite Version:     [3.53.3]
  Plex Version:       [1.43.4]
  Plex Log Dir:       [/share/CACHEDEV1_DATA/.qpkg/PlexMediaServer/Library/Plex Media Server/Logs]
  App Support Dir:    [/share/CACHEDEV1_DATA/.qpkg/PlexMediaServer/Library]
  Database Dir:       [/share/CACHEDEV1_DATA/.qpkg/PlexMediaServer/Library/Plex Media Server/Plug-in Support/Databases]
  Database Temp Dir:  [/share/CACHEDEV1_DATA/.qpkg/PlexMediaServer/Library/Plex Media Server/Plug-in Support/Databases/dbtmp]
  Main DB Path:       [/share/CACHEDEV1_DATA/.qpkg/PlexMediaServer/Library/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db]
  Blobs DB Path:      [/share/CACHEDEV1_DATA/.qpkg/PlexMediaServer/Library/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.blobs.db]
  Cache Dir:          [/share/CACHEDEV1_DATA/.qpkg/PlexMediaServer/Library/Plex Media Server/Cache/PhotoTranscoder]
  Log File:           [/share/CACHEDEV1_DATA/.qpkg/PlexMediaServer/Library/Plex Media Server/Plug-in Support/Databases/DBRepair.log]
  Pid File:           [/share/CACHEDEV1_DATA/.qpkg/PlexMediaServer/Library/Plex Media Server/plexmediaserver.pid]
  Temp Dir (Local):   [/share/CACHEDEV1_DATA/.qpkg/PlexMediaServer/Library/tmp]
  System Temp:        [/share/CACHEDEV1_DATA/.qpkg/PlexMediaServer/Library/tmp]
  Main Schema Key:    [202601121053]
  Main Schema Path:   [/share/CACHEDEV1_DATA/.qpkg/PlexMediaServer/Library/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db-2026-08-29]
  Blobs Schema Key:   [202601121053]
  Blobs Schema Path:  [/share/CACHEDEV1_DATA/.qpkg/PlexMediaServer/Library/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.blobs.db-2026-08-29]
 
  Sqlite3 Cache Size  [0]
  Sqlite3 Page Size   [0]
  DBRepair Notify Cmd []
 
  Pidof Utility:      [pidof]
  FTS Query:          [SELECT name FROM sqlite_master WHERE sql LIKE '%FTS%';]
  Have Start/Stop:    (Yes)
  Start Command:      [/etc/init.d/plex.sh start]
  Stop Command:       [/etc/init.d/plex.sh stop]
 
  --- Stack State ---
  Stack Top:          [0]
  Stack Count:        [0]
                      (No History to show.)
------------------------------------------------------

Hope this helps!

@smwinn

That is actually normal with PMS.

It was known to Plex Engineering and me that some entries were missing the ‘parent’ links in the DB.

PMS 1.43.4 has started addressing that.
For versions prior to 1.43.4, I address it.

This is all part of the big work I’ve been doing .

The ‘(unknown)’ should be the actual library section name.
Let me check that now too while I’ve got it all open.

Might I be able to trouble you for a copy of your main DB (Zip)
so I can debug against it and see where I’m missing ?

Yeah, it was the “unknown” library that I was referring to.