Repair a Corrupt Database

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.

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 deleting 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.)

Related Page: Where is the Plex Media Server data directory located?
Related Page: Restore a Database Backed Up via 'Scheduled Tasks'

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

To see how badly corrupted the database might be:

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.

  1. sqlite3 com.plexapp.plugins.library.db .dump > dump.sql
  2. rename com.plexapp.plugins.library.db com.plexapp.plugins.library.db.original
  3. 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

OS X / macOS

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

To see how badly corrupted the database might be:

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.

  1. sqlite3 com.plexapp.plugins.library.db .dump > dump.sql
  2. mv com.plexapp.plugins.library.db com.plexapp.plugins.library.db.original
  3. 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

To see how badly corrupted the database might be:

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.

  1. sqlite3 com.plexapp.plugins.library.db .dump > dump.sql
  2. mv com.plexapp.plugins.library.db com.plexapp.plugins.library.db.original
  3. 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