If you have not already, we suggest setting your Plex username to something else rather than email which is displayed on your posts in forum. You can change the username at https://app.plex.tv/desktop#!/account
Welcome to our forums! Please take a few moments to read through our Community Guidelines (also conveniently linked in the header at the top of each page). There, you'll find guidelines on conduct, tips on getting the help you may be searching for, and more!

Manual Database Optimization using command line

ChuckPAChuckPA Posts: 22,186Members, Plex Pass, Plex Ninja, Plex Team Member Plex Team Member
edited March 13 in Linux Tips

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

Please DISABLE Verbose logging until requested

Please search before posting

Primary support: Linux, Synology, and QNAP

Please remember to report back. This benefits others.

Useful links

 Installation and Basic Setup |  Media Preparation (How to name your media files)  |  Linux Permissions 

 Handling TV Specials | Handling Movie extras  |  Nas Compatibility

 Reporting Plex Server issues | Plex Media Server FAQ | Linux Tips

 

Other useful guides: Local Subtitles | The Plex "dance" | Synology FAQ | PMS Release Announcements

Hosts: Fedora, QNAP, Synology, most Linux distros in VM

No technical support via PM unless offered

Please remember to mark the appropriate answer(s) which solved your issue.

 
This discussion has been closed.