Library.db size more than doubled in latest version

The :plexpass tag was deprecated 4 years ago. It automatically installs the beta version.

https://hub.docker.com/r/plexinc/pms-docker/tags?name=plexpass

The “Server update channel” setting is irrelevant for the docker container. The installed version is dictated by the docker image tag. See the latest readme for the available tags.


Side note: the readme on dockerhub is out-of-date and refers to the old tags. @ChuckPa you should poke someone to fix this.

https://hub.docker.com/r/plexinc/pms-docker#:~:text=your%20own%20user.-,Tags,-In%20addition%20to

1 Like

@SwiftPanda16

Thank you. I haven’t looked or noticed.

I will indeed poke folks.

… poked.

1 Like

this was exactly what was wrong with my system, 18GB db on spinning rust took way too long to backup, getting db timeouts, script shrank it down to 423MB, then ran a DBRepair.sh vacuum and brought it down to 300MB. Brilliant, thanks ChuckPa!

1 Like

@rdeck1

Now that you have it down to manageable size, I recommend a full optimization pass (auto) and get everything resequenced and reindexed for best performance.

1 Like

Did a ./DBRepair.sh AUTO VACU PRUN PURG - went down from 423MB to 302MB, very nice. Added that to run daily (with stop/start before & after)

1 Like

@rdeck1

You don’t need a Vacuum in that sequence. The db reload (auto) does better than a vacuum because the tables are loaded from external and built perfectly compacted.

This explains a lot. I’ve changed it to plexinc/pms-docker:public and the startup script reverted back to version 1.41.8.9834.
Is this the expected behavior that unknown tags default to the beta version?

Your script successfully deflated the database from 55GB back to 430MB in around an hour on the same hardware plex is running. (Plex should be shipped with your script because the default Optimize Database did not get through it :sweat_smile:

I’ve edited the paths on my windows machine using notepad++ with success and followed your instructions. The plex docker did not find the sudo command but it ran without it just fine :slight_smile:

1 Like

Thanks for the script!
My db file shrank from 103GB to 100MB
Took about 2 hours 10 minutes according to the timestamps of the files
Hopefully it will be more stable now!

Thanks again…

1 Like

Hi guys, does anyone have an easy to follow guide for sorting this problem out on a Windows 11 install of Plex please? Mine is still huge and pretty slow, but it can’t seem to sort itself out. When it tries to run the maintenance, after a few hours I get a notification from Tautulli telling me that it’s gone offline, and it’s unresponsive when I try to access.

Kind of needs to be an idiots guide…! :slight_smile:

Thanks

Read this post, download the zip file and ask chat gpt nicely :slight_smile:

(You can feed chatgpt the script and some text from this thread. Tell chatgpt that you are a novice and give it feedback after each step you do)

1 Like

Thanks for that. I’m using ChatGPT. I had to get it to edit the bat file because it didn’t like the paths, so I got ChatGPT to create a modified one (clever, ain’t it!). Now it starts to run, but I get this error;

Error: stepping, no such collation sequence: icu_root
ERROR: VACUUM operation failed.

ChatGPT tells me that;

Plex’s internal database uses a version of SQLite compiled with ICU support (International Components for Unicode). This allows case-insensitive and locale-aware sorting, which is not supported by the regular command-line SQLite tools downloaded from sqlite.org.

So when sqlite3.exe tries to read the database and hits something like:

sql

CopyEdit

ORDER BY title COLLATE icu_root;

it crashes, because it doesn’t know what icu_root is.

and says my option is to use the Plex Web>Optimize database tool, but when I run that my Plex just crashes.

It says;
If you’re running Plex on Windows, you’re kind of stuck unless you:

  • Find a precompiled sqlite3.exe with ICU support
    (hard to find and risky unless from a trusted source)

Does anyone have precomfiled sqlite3.exe please?

Use the Plex SQLite.exe file located at the root of the Plex Media Server install dir

2 Likes

Not having much success! I get so far and then ChatGPT tells me I’ve run out of use and to try again tomorrow!

It seems my Plex DB is corrupt or locked, so it’s telling me to create a temporary Plex in Docker, but all three of the commands it’s telling me to use to pull the image comes up with errors, and now it’s out of usage again!

I’ll see if Gemini AI can get me further…!

OK, so Gemini was even more confusing and kept responding with “very perplexing!”
I ditched the amended bat that ChatGPT created (it had made a LOT of amendments!) and retried with the original Chuck bat after going through and double checking all the paths, etc and now it seems to be running. Phew! It’s listed the directory of the folder and says ==== Deflating into new DB
so hopefully it is now doing it!
Fingers crossed!

Looks like you’re on the good track. Just give it some time :slight_smile:

Has anyone gotten the windows batch file to work properly? I don’t think its properly calling Plex SQL Lite, as there are no commands to do so after it echos “Deflating into new DB”. The create and alter commands have no prefix to execute PSQL.

I tested the Windows deflate bat file and found that it doesn’t determine the actual location of the plex sqlite exe and the location of the database file. It just assumes the default locations, or rather leaves it to the user to edit the bat file and fill in the locations.
I copied the detection routines from the repair bat file over, so we end up with

@echo off
setlocal EnableDelayedExpansion

REM Windows .BAT script to deflate Plex Media Server database
REM Run this script under the same Windows user account that you use to run Plex Media Server

REM Find PMS installation location.
for /F "tokens=2* skip=2" %%a in ('REG.EXE QUERY "HKCU\Software\Plex, Inc.\Plex Media Server" /v "InstallFolder" 2^> nul') do set "PSQL=%%b\Plex SQLite.exe"

if not exist "%PSQL%" (
  REM InstallFolder might be set under HKLM, not HKCU
  for /F "tokens=2* skip=2" %%a in ('REG.EXE QUERY "HKLM\Software\Plex, Inc.\Plex Media Server" /v "InstallFolder" 2^> nul') do set "PSQL=%%b\Plex SQLite.exe"
)

REM If InstallFolder wasn't set, or the resulting file doesn't exist, iterate through the
REM PROGRAMFILES variables looking for it. If we still can't find it, ask the user to provide it.
if not exist "%PSQL%" (
  if exist "%PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe" (
    set "PSQL=%PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe"
  ) else (
    if exist "%PROGRAMFILES(X86)%\Plex\Plex Media Server\Plex SQLite.exe" (
      echo NOTE: 32-bit version of PMS detected on a 64-bit version of Windows. Updating to the 64-bit release of PMS is recommended.
      set "PSQL=%PROGRAMFILES(X86)%\Plex\Plex Media Server\Plex SQLite.exe"
    ) else (
      echo Could not determine SQLite path. Please provide it below
      echo Normally %PROGRAMFILES%\Plex\Plex Media Server\Plex SQLite.exe
      echo.
      REM Last ditch effort, ask the user for the full path to Plex SQLite.exe
      set /p "PSQL=Path to Plex SQLite.exe: "
      if not exist "!PSQL!" (
        echo "!PSQL!" could not be found. Cannot continue.
        goto :EOF
      )
    )
  )
)

REM Find PMS database location
for /F "tokens=2* skip=2" %%a in ('REG.EXE QUERY "HKCU\Software\Plex, Inc.\Plex Media Server" /v "LocalAppDataPath" 2^> nul') do set "DBDIR=%%b\Plex Media Server\Plug-in Support\Databases"
if not exist "%DBDIR%" (
  if exist "%LOCALAPPDATA%\Plex Media Server\Plug-in Support\Databases" (
    set "DBDIR=%LOCALAPPDATA%\Plex Media Server\Plug-in Support\Databases"
  ) else (
    echo Could not determine Plex database path.
    echo Normally %LOCALAPPDATA%\Plex Media Server\Plug-in Support\Databases
    echo.
    goto :EOF
  )
)

set "CPPL=com.plexapp.plugins.library.db"

REM Sanity checks
if not exist "%DBDIR%" (
    echo ERROR: No such directory '%DBDIR%'
    exit /b 1
)
if not exist "%PSQL%" (
    echo ERROR: Cannot find 'Plex SQLite' at '%PSQL%'
    exit /b 2
)
if not exist "%DBDIR%\%CPPL%" (
    echo ERROR: Cannot find or no write permission for '%CPPL%'
    exit /b 3
)

echo ==== Current listing
dir "%DBDIR%"

REM Change to the databases directory
cd /d "%DBDIR%"

REM Remove output if exists
if exist "new.com.plexapp.plugins.library.db" del /f "new.com.plexapp.plugins.library.db"

echo ==== Deflating into new DB
echo CREATE TABLE temp_bandwidth as select * from statistics_bandwidth where account_id not null; > temp.sql
echo DROP TABLE statistics_bandwidth; >> temp.sql
echo ALTER TABLE temp_bandwidth RENAME to statistics_bandwidth; >> temp.sql
echo CREATE INDEX 'index_statistics_bandwidth_on_at' ON statistics_bandwidth ('at'); >> temp.sql
echo CREATE INDEX 'index_statistics_bandwidth_on_account_id_and_timespan_and_at' ON 'statistics_bandwidth' ('account_id', 'timespan', 'at'); >> temp.sql
echo VACUUM main into './new.com.plexapp.plugins.library.db'; >> temp.sql

"%PSQL%" "%CPPL%" < temp.sql
set Result=%ERRORLEVEL%

REM Clean up temporary SQL file
del /f temp.sql

REM Check for errors
if %Result% NEQ 0 (
    echo ERROR: Error code %Result% from deflate. Seek assistance
    exit /b 4
)

REM Confirm we have a DB
set OK=1
if not exist "new.com.plexapp.plugins.library.db" set OK=0

REM Confirm not zero size (using dir to get file size)
for %%F in ("new.com.plexapp.plugins.library.db") do set NewSize=%%~zF
if !NewSize! LEQ 300000 set OK=0

REM Abort if not OK
if %OK% NEQ 1 (
    echo ERROR: Something went wrong. Exiting.
    exit /b 31
)

REM Get file ownership and permissions (Windows equivalent)
REM Note: Windows doesn't have direct chown/chmod equivalents; using icacls for permissions info
echo ========== DEBUG ================
echo Owner: (Use icacls to check manually if needed)
icacls "%CPPL%"
echo New Size: %NewSize% bytes

REM Move existing DBs
echo Moving existing DB to '-bloat'
move "%CPPL%" "com.plexapp.plugins.library.db-bloat"
if exist "%CPPL%" move "%CPPL%" "%CPPL%-bloated"

echo Removing WAL and SHM if exist
if exist "%CPPL%-wal" del /f "%CPPL%-wal"
if exist "%CPPL%-shm" del /f "%CPPL%-shm"

REM Move new DB into position
echo Making new DB active
move "new.com.plexapp.plugins.library.db" "%CPPL%"

REM Set permissions (restore original permissions if possible)
REM Note: Windows permissions are complex; may need manual adjustment
echo Restoring permissions (check manually if needed)
icacls "%CPPL%" /reset

echo New databases directory contents
dir "%DBDIR%"

echo Done.
exit /b 0

4 Likes

The revised script you posted worked, thanks! It ran for approximately 30 minutes and reduced my 51GB DB to 370MB.