Manual database optimization using the 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 without the UI by sending the command directly to PMS.
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 "/PATH/TO/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