Manual Database Optimization using command line



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


# 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\?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