Manual Database Optimization using command line

server-linux-tips

#1

If you can't get to the UI because it times out (your database is really fragmented). This will allow you to invoke database optimization.

Manual CLI/curl Database Optimization with PMS running

#!/bin/sh

# Get the contents of the Preferences file, keep only what we need,  push to a temp, then use it in the curl command

# you may remove the sudo if not needed to read your Preferences.xml

cat "/home/plexdir/Library/Application Support/Plex Media Server/Preferences.xml" |  \
sed -e 's;^.* PlexOnlineToken=";;' | sed -e 's;".*$;;' | tail -1 > /tmp/plex.tmp

curl --request PUT http://127.0.0.1:32400/library/optimize\?async=1\&X-Plex-Token=`cat /tmp/plex.tmp`

rm -f /tmp/plex.tmp

Manual shell/sqlite3 Database Optimization with PMS stopped

This is an advanced method for those who are comfortable with using the shell and direct hands-on of the DB.

sudo sh

service plexmediaserver stop
cd "/var/lib/plexmediaserver/library/Application Support/Plex Media Server/Plug-in Support/Databases"

mv com.plexapp.plugins.library.db com.plexapp.plugins.library.prev.db
rm com.plexapp.plugins.library.db-???

sqlite3 com.plexapp.plugins.library.prev.db .dump > dbdump.sql
sqlite3 com.plexapp.plugins.library.db < dbdump.sql
chown plex:plex com.plexapp.plugins.library.db

service plexmediaserver start

Note: You will still need to perform Empty-Trash and Clean-Bundles as normal regardless of technique


#2