Library.db size more than doubled in latest version

FYI my database went from 300mb to 89gb in the matter of a bit over a week. I noticed when my servers disk space was nearly full and found it, along with a few backup copies, taking up all this room.

While I probably could have just restored the 300mb backup, I decided to fix the database as this is the same database I have been running since a original install in 2016. It has some sentimental value :rofl:

24 hours later the process is about 85% complete running the purge command. (I can see the temporary data files it makes when chugging through, single thread, through data on a i5 11th gen and EVO 980 SSD.). I’ll compact/vacuum when done and report results.

FYI before I manually did this, I tried the database tools within the Plex server-management page. No dice. It would run for 30 minutes and crash and restart Plex. So the fix being built into the updated app doesn’t work for all. The sheer size (90gb!!) was probably overwhelming. I suspect others with this issue with a LARGE database like mine. I’m using the latest Win64 build of SQLite directly from their site.

Luckily I have JellyFin installed on the same server as a backup as I’ve had to keep Plex off for more than a day now. (I do this for odd media files that sometimes Plex has issues with but JellyFin may process better. Plus their browser H265 support is nice for watching at work without having to install an app).

1 Like

Is 1.41.7.9799 supposed to fix database growth?

  • (Statistics) The fix for Bandwidth reporting was reverted as it was causing massive database growth

I have 1.41.6.9685 running in Windows. The com.plexapp.plugins.library.db files is 672,915 KB.

With 1.41.7.9799 running in Docker (OMV) the db file is 1,582,747 KB.

The Windows install has >1,800 Movies, >31,000 TV Episodes and >22,000 songs.

The Docker install only has the >22,000 songs, no Movies or TV Episodes at all. Yet the db file is over 2x larger. I installed this today. It’s not a db that grew over time.

1 Like

On my side the database stopped growing after the update. As mentioned before I had to clean the table manually to reduce disk space usage. But now after 2 days it’s not growing anymore. Thank you !

I reported this several months ago as well, and even with AV exclusions the files were not removed:

Video preview thumbnail generation leaves behind temp BIF files - Plex Media Server / Desktops & Laptops - Plex Forum

I had to restore a database from a week ago, as the previous backup was already bloated (1GB had grown to 27GB), and the repair failed to resolve the bloat. Now re-scanning the media that was added in the interim, hoping to avoid a repeat.

I wanted to share my experience with this as well, but please excuse my notes as I just jotted some items down quickly last night and was playing around with this rather late. I don’t really have track of which version my bloating issue started occurring at, but I tend to keep my PMS version up to date. I recently went through a migration from Windows 10, to Docker Desktop on Windows 11 and using the official Plex PMS docker- imageplexinc/pms-docker:plexpass. I like this version as it auto updates when the container restarts.

Migrated approximately January 2025 and my DB file was already somewhere around 30GB, I think. I am a little fuzzy on this, or it could be that my whole PMS folder was around 40GB. I only partially remember while transferring everything to a new system. Right now, post fix, it is sitting at about 84GB as I’ve added quite a bit to it since migration. Decided I wanted to learn and play around in Docker so that’s the reason why running it on Windows 11 in Docker Desktop. Thinking I will go back to a dedicated machine in future.

Some library stats:
Movies: 900
Episodes: 7500
Music: 66,000

I did a couple tests last night after learning about this and also just wanted to help if there are any other Windows users as I had to hunt around a bit to figure out how to run the commands, both from within the container after having stopped PMS with the container still running, and also tested just doing the fix via Windows.

The Database repair to “delete from statistics_bandwidth where account_id is NULL;” seems to run faster natively in Windows. It took longer running in the Linux docker container shell. I’ve noticed this slowness with loading/running Lidarr as well in my docker container of Lidarr with no add-ons seems to take much longer to load than it did on my older Win10 system than running in a docker container on Win11. I have not been happy with the performance, but perhaps there are some Docker Desktop settings I need to adjust? Running the config files for both PMS and Lidarr on a Samsung 990 Pro NVMe. Running Intel Core i7 14700F with 64 GB RAM.

The tests runs took my 46 GB db file and took it to 459 MB for both tests after running
’ VACUUM; '.
The .db-wal file (temp) was 36.6 GB, deleted after exiting Plex SQLite
Windows ~1.5 hours
Docker container ~4 hours
I looked at a copy of the db prior to repair using HeidiSQL, there was 811,426,257 rows total in the statistics_bandwidth table for me.
This was reduced to 19,839 rows after running the command in this topic.

Running in the Docker Container shell (Slow method, at least for me):

  1. Shutdown PlexPMS but leave the container running
    #./plex_service.sh -d
  2. Change to your database directory
    #cd "/config/Library/Application Support/Plex Media Server/Plug-in Support/Databases/"
  3. Backup your database per instructions from Plex: Repair a Corrupted Database
  4. Run Plex SQLite
    #"/usr/lib/plexmediaserver/Plex Media Server" --sqlite com.plexapp.plugins.library.db
  5. Run the command listed in this topic and wait a Million Years. :grimacing:
    sqlite> delete from statistics_bandwidth where account_id is NULL;
    fixes bloated database for this issue as stated above
  6. Vacuum
    sqlite> VACUUM;
  7. Quit
    sqlite> .quit
  8. Restart PMS
    #./plex_service.sh -u (-d for down, -u for up, -r for restart)
    or
    manually restart the container.

Running from Windows Command Prompt:
I had to download and install PMS for Windows, just to make sure I had the Plex SQLite.exe. I did also learn how to copy it out from the docker container, but I think it needed the Plex PMS .exe to run properly.

Copy files from docker container:
C:\>docker cp *container_name*:/usr/lib/plexmediaserver/ c:\temp

  1. Shutdown PlexPMS but leave the container running or just fully shut down the container as it doesn’t need to be running.
    #./plex_service.sh -d
  2. Backup your database per instructions from Plex: Repair a Corrupted Database
  3. Using Windows Command Prompt, Run Plex SQLite to open your db file (edit as needed to point to you Docker Container path in Windows)
    C:\>"C:\Program Files\Plex\Plex Media Server\Plex SQLite.exe" "C:\path\to\Docker PMS\Library\Application Support\Plex Media Server\Plug-in Support\Databases\com.plexapp.plugins.library.db"
  4. Run the command listed in this topic and wait for less time.
    sqlite> delete from statistics_bandwidth where account_id is NULL;
    fixes bloated database for this issue as stated above
  5. Vacuum
    sqlite> VACUUM;
  6. Quit
    sqlite> .quit
  7. Restart PMS
    #./plex_service.sh -u (-d for down, -u for up, -r for restart)
    or
    manually (re)start the container.

Worked for me in my situation. Things felt a bit snappier opening and navigating Plex on Desktop/phone/tv all on the network, but haven’t had any feedback from anyone else who uses my server yet. I just hope these commands help and save some time for some of you. Appreciate any thoughts or inputs. Thank you.

4 Likes

Thanks for posting this. More reassurance for those trying to make the fix before Plex releases the minor rev that will make this mess go away. I run Plex natively, everything else in containers, so I ran a similar set of commands from CLI. I guess my question is what is fair game to delete once the cleanup process has completed? If this weren’t an issue of file footprint, then I’d just tar the ‘Databases’ folder for safe keeping and delete files judiciously. I CAN tar and save to my RAID5 location (ample space), but I’d just assume blow away the offending DBs (and their backups). Your opinion is quite welcome, cheers!

Is the process of restoring the database from a backup on Synology NAS detailed somewhere? Would prefer ELI5 instructions if at all possible, as I just haven’t familiarized myself with this machine that much yet.

I assume it’s not as simple as stopping PMS, then deleting the current db file and replacing with a backup db file by giving it the current db file name, then restarting PMS and triggering re-scans of all libraries, is it?

My current database is up to 42.85 GB and the db-wal file is now 41.82 GB and growing. I have a database backup from May 12th that’s only 643.6 MB, so would like to restore from that file.

When restoring, make sure you remove the existing wal and shm files.

1 Like

My db went from 1.98 GB to 63.9 GB recently. I still need to go through the discussions in this thread to see if I can clean it up

I’ve has sqlite cleaning up the DB for the last 4. 5 hours! Hopefully it’s done soon, my remote watchers are getting restless…ungrateful tossers, the lot of 'em…

Not sure of your setup, I’m running a native install on Ubuntu 24.04 LTS, so:

  1. sudo systemctl stop plexmediaserver.service (have to stop the PMS service first)
  2. sudo /usr/lib/plexmediaserver/Plex\ SQLite (to evoke the SQLite interface)
  3. cd /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Plug-in\ Support/Databases/ (to change to the DBs directory)
  4. sqlite> .open com.plexapp.plugins.library.db (to open the offending DB)
  5. sqlite> DELETE FROM statistics_bandwidth WHERE account_id IS NULL; (to delete the DB entries where the account_id is NULL)
  6. sqlite> VACUUM; (to remove the blank DB rows, reducing the overall size of the DB)
  7. sqlite> .quit (exit the SQLite interface)
  8. sudo systemctl start plexmediaserver.service (startup the PMS service and check results)
1 Like

Hey folks, @ChuckPa updated his PlexDBRepair tool to v1.10.06.

It now removes the excess statistics entries from the database.

It works on Linux & Mac systems.

For those who already have the tool, update to 1.10.06 1.11.00. The AUTO option will remove the statistics. There is also an unlisted option, COUNT (or 30), that lists the number of database entries for various items, including statistics_bandwidth, the one that is bloating the Plex db.

The README has information on how to run in Docker containers, on various NAS, etc.

If you’ve a “bare metal” install on Ubuntu (or similar Linux distros):

Download the tool:

$ wget -O DBRepair.sh https://github.com/ChuckPa/DBRepair/releases/latest/download/DBRepair.sh

Make it executable:
$ chmod a+x DBRepair.sh

Run it:
$ sudo ./DBRepair.sh

STOP: Plex Media Server must be stopped
COUNT: If you want to see the number of items, look for statistics_bandwidth
AUTO: To check, repair, etc. & remove statistics entries
START: To restart Plex Media Server
EXIT: To exit and remove temp/working files.

If desired, you can run it as one command:
$ sudo ./DBRepair.sh stop auto start exit
$ sudo ./DBRepair.sh stop count auto count start exit ← to see before/after numbers for statistics_bandwidth.

Expect it to take quite some time to run, as it is performing the same deletions as if you were using the SQLite commands.


2025.05.25: Updated with current version number and GitHub location.

8 Likes

To add to @FordGuy61

As it runs, after checking the DBs, it will remove the records before Exporting.

It will notify you what it’s doing.

Once Engineering has resolved the issue permanantly, I’ll remove this patch from DBRepair.

EDIT: For some folks , there was a lot of junk spewed to the console when you wanted to update interactively. I’ve also resolved this in 1.10.06. There is more work to do but the important visual part is done.

6 Likes

Jeez, this explains a lot!

Thanks a million @ChuckPa (or should I say one billion two hundred eighty-five million six hundred thirty-nine thousand one hundred, in my case??)

And thanks @FordGuy61

Here’s what I am dealing with: statistics_bandwidth 1285639100

DB was sitting at 74GB in my case.

@cybrnook

What is the current DB size ?

com.plexapp.plugins.library.db is 74GB in my case

your script I think is running the export/cleanup task and it’s copy of the DB so far is about 6GB~ and growing.

Note: very first time ever running this (docker container, but browsing via windows explorer)

You went from 74GB → x GB (or x MB) → 6GB now?

Did this all occur as you upgraded to 1.41.7 ?

If so, is there any harm downgrading to 1.41.6 or 1.41.5 ?

If you can, it should give you functionality and give Engineering time to work this out.

Apologies, I wasn’t tagging you to ask for help or anything. More just saying thanks for your script.

I’ve since rolled the DB back and it’s now down from 74GB to a more realistic 82MB.

Was just saying thanks for your work.

1 Like

@ChuckPa

Any chance the permanent fix (*.deb) will permanently delete the bad/corrupt/extraneous DBs? Or might you add to your already spectacular DBRepair script, as an execution argument?

I just want to clean up that directory without issue. Thanks in advance!

@maxroberts22

I haven’t had opportunity to speak with DrZoidberg about this
(I’ve been out sick).

I would expect the permanent fix(es) will be in executable (in the .DEB) file as an integral part of PMS.


I’ve added the one obvious cleanup to DBRepair which I saw mentioned internally. Once everything is back to normal, I’ll remove my ‘patch’ from DBRepair. It’s intended as a stopgap measure only.

I need to ask if there are any additional interrim measures I can apply to help.
I don’t want to overstep here as this is an ongoing issue.

2 Likes