Though rare, it is possible for your main Plex Media Server database to become corrupted. For instance, it might happen if the computer is turned off without first quitting Plex Media Server. In such a situation, you can attempt to repair the database.
This article is for Plex Media Server version 1.22.0 and earlier. If using version 1.23.2 and newer see Repair a Corrupted Database
Tip!: It’s always a good idea make a backup copy of the database file before doing any work on it.
In many cases, you may also be able to restore a database copy that was backed up via the Scheduled Tasks feature.
The database file will be located at /Plug-in Support/Databases/com.plexapp.plugins.library.db
inside the main Plex Media Server data directory. The data directory location can vary by operating system and device. The commands listed below will assume the default server data directory locations.
Note: You can also simply delete the com.plexapp.plugins.library.db
database file while the Plex Media Server is not running. Restarting the server will then restore your server to a nearly-fresh install state. (i.e. You will lose your existing libraries and need to recreate them, but you won’t be affecting your content itself.)
Warning: With the instructions below, if you run all of the “Check for Corruption” instructions aprior to running the “Run a Repair” instructions, you will receive errors related to steps 2 & 3 of the latter. That is expected and the errors won’t affect anything.
Related Page: Where is the Plex Media Server data directory located?
Related Page: Restore a Database Backed Up via 'Scheduled Tasks'
Related Page: For Plex Media Server 1.23.2 and newer Repair a Corrupted Database
Windows
Windows installs don’t come with SQLite3 tools installed by default. However, you can download and install them yourself from the SQLite website.
Related Page: SQLite.org download page
Make sure you quit/exit your Plex Media Server so that it is not running. The following commands are run in the Command Prompt application. When running the commands, be sure to enclose paths in quotes to handle spaces in paths. First, simply switch over to the directory containing the database.
cd "%LOCALAPPDATA%\Plex Media Server\Plug-in Support\Databases"
If you haven’t added the SQLite executable to your path environment, then it’s easiest to simply copy the sqlite3.exe
executable file into the above directory so that it’s easy to run.
Check for Corruption
You can run commands to check how corrupt the database might be. Even if the results come back “OK”, it’s still possible for there to be issues with a database, though.
-
copy com.plexapp.plugins.library.db com.plexapp.plugins.library.db.original
-
sqlite3 com.plexapp.plugins.library.db "DROP index 'index_title_sort_naturalsort'"
-
sqlite3 com.plexapp.plugins.library.db "DELETE from schema_migrations where version='20180501000000'"
-
sqlite3 com.plexapp.plugins.library.db "PRAGMA integrity_check"
Run a Repair
Even if the integrity check doesn’t return errors, it can still sometimes help to try and repair the database. In order to try and “repair” the database, you can perform a dump followed by a restore to get it back to normal. Run the following commands in the Command Prompt in order.
-
copy com.plexapp.plugins.library.db com.plexapp.plugins.library.db.original
-
sqlite3 com.plexapp.plugins.library.db "DROP index 'index_title_sort_naturalsort'"
-
sqlite3 com.plexapp.plugins.library.db "DELETE from schema_migrations where version='20180501000000'"
-
sqlite3 com.plexapp.plugins.library.db .dump > dump.sql
-
del com.plexapp.plugins.library.db
-
sqlite3 com.plexapp.plugins.library.db < dump.sql
Prior to restarting your Plex Media Server, you should also delete (or backup and move elsewhere) the following two files if they exist alongside the original database:
com.plexapp.plugins.library.db-shm
com.plexapp.plugins.library.db-wal
macOS / OS X
Make sure you quit/exit your Plex Media Server so that it is not running. The following commands are run in the Terminal application. When running the commands, you need to escape any spaces in paths. First, simply switch over to the directory containing the database.
cd ~/Library/Application\ Support/Plex\ Media\ Server/Plug-in\ Support/Databases/
Check for Corruption
You can run commands to check how corrupt the database might be. Even if the results come back “OK”, it’s still possible for there to be issues with a database, though.
-
cp com.plexapp.plugins.library.db com.plexapp.plugins.library.db.original
-
sqlite3 com.plexapp.plugins.library.db "DROP index 'index_title_sort_naturalsort'"
-
sqlite3 com.plexapp.plugins.library.db "DELETE from schema_migrations where version='20180501000000'"
-
sqlite3 com.plexapp.plugins.library.db "PRAGMA integrity_check"
Run a Repair
Even if the integrity check doesn’t return errors, it can still sometimes help to try and repair the database. In order to try and “repair” the database, you can perform a dump followed by a restore to get it back to normal. Run the following commands in the Terminal in order.
-
cp com.plexapp.plugins.library.db com.plexapp.plugins.library.db.original
-
sqlite3 com.plexapp.plugins.library.db "DROP index 'index_title_sort_naturalsort'"
-
sqlite3 com.plexapp.plugins.library.db "DELETE from schema_migrations where version='20180501000000'"
-
sqlite3 com.plexapp.plugins.library.db .dump > dump.sql
-
rm com.plexapp.plugins.library.db
-
sqlite3 com.plexapp.plugins.library.db < dump.sql
Prior to restarting your Plex Media Server, you should also delete (or backup and move elsewhere) the following two files if they exist alongside the original database:
com.plexapp.plugins.library.db-shm
com.plexapp.plugins.library.db-wal
Linux
Linux installs don’t come with SQLite3 tools installed by default. However, you can download and install them yourself from the SQLite website.
Related Page: SQLite.org download page
Make sure you quit/exit your Plex Media Server so that it is not running. The following commands are run in the Terminal application. When running the commands, you need to escape any spaces in paths. First, simply switch over to the directory containing the database.
cd $PLEX_HOME/Library/Application\ Support/Plex\ Media\ Server/Plug-in\ Support/Databases/
Check for Corruption
You can run commands to check how corrupt the database might be. Even if the results come back “OK”, it’s still possible for there to be issues with a database, though.
-
cp com.plexapp.plugins.library.db com.plexapp.plugins.library.db.original
-
sqlite3 com.plexapp.plugins.library.db "DROP index 'index_title_sort_naturalsort'"
-
sqlite3 com.plexapp.plugins.library.db "DELETE from schema_migrations where version='20180501000000'"
-
sqlite3 com.plexapp.plugins.library.db "PRAGMA integrity_check"
Run a Repair
Even if the integrity check doesn’t return errors, it can still sometimes help to try and repair the database. In order to try and “repair” the database, you can perform a dump followed by a restore to get it back to normal. Run the following commands in the Terminal in order.
-
cp com.plexapp.plugins.library.db com.plexapp.plugins.library.db.original
-
sqlite3 com.plexapp.plugins.library.db "DROP index 'index_title_sort_naturalsort'"
-
sqlite3 com.plexapp.plugins.library.db "DELETE from schema_migrations where version='20180501000000'"
-
sqlite3 com.plexapp.plugins.library.db .dump > dump.sql
-
rm com.plexapp.plugins.library.db
-
sqlite3 com.plexapp.plugins.library.db < dump.sql
-
chown plex:plex com.plexapp.plugins.library.db
Prior to restarting your Plex Media Server, you should also delete or backup and move elsewhere the following two files if they exist alongside the original database:
com.plexapp.plugins.library.db-shm
com.plexapp.plugins.library.db-wal