How to Optimize the Database

Much of the metadata you see in Plex for each of your media items is stored in an SQLite database. The Plex database is located in the data directory on the server and is accessed frequently.

Over time the database can become fragmented and contain unused data, which can affect the performance of your Plex server. To keep your database running as performant as possible, you should run the optimize database command at least once a week.

Below are three ways that you can run the optimize database command in Plex.

It is good practice to backup your database before performing any actions on it.

How to Optimize the Database in Plex

Table of contents

How to optimize database
The step-by-step guide for running the optimize database option from the Plex Web app.
Using the troubleshooting option
These steps explain how to use the optimize database option found in the troubleshooting section of Plex.
Scheduling optimize database in Plex
Step-by-step instructions for scheduling the optimize database command to run on a schedule in Plex.
Running optimize database on-demand
Discusses how you can run the optimize database command at any time without using the Plex Web app.

How to optimize the database

As mentioned above, the Plex database can cause performance issues with your Plex server over time. This is especially true if you have added or deleted many media items to your Plex server.

Plex has a built-in command to optimize the database. You can manually run this command from the Plex Web app using the following steps:

  1. From Plex, click the More link.
    The More Option in Plex.
    The 'More' Option in Plex
  2. Move your mouse cursor over your server name from the menu on left. Click the three dots that appear, and then select Manage Server->Optimize Database from the menu that appears.
    The Optimize Database Option in Plex.
    The 'Optimize Database' Option in Plex
  3. Click the Optimize button.
    The Optimize Database Dialog in Plex.
    The 'Optimize Database' Dialog in Plex

Using the troubleshooting option

You can also optimize the database using the option under the troubleshooting section found in the Plex settings. Use the following steps to optimize the database using this option.

  1. Open a Web browser and navigate to your Plex server.
  2. Log into your Plex server with an administrator account.
  3. Click the Settings icon - the wrench - in the upper-right corner of the Plex server page.
  4. On the left menu, click the Troubleshooting option under the Manage section.
  5. Click the Optimize Database button and wait for it to complete.
    Using the Optimize Database button in Plex's Troubleshooting section.
    Using the Optimize Database button in Plex's Troubleshooting section
  6. Once completed, the message Optimize database complete will appear beside the button.
    Optimizing the database in Plex is completed.
    Optimizing the database in Plex is completed

Once the above steps in the previous sections are run, the Plex database is optimized to keep your Plex server from having performance issues.

Scheduling optimize database in Plex

Running the optimize database option in Plex is a good way to keep your Plex database running as fast as possible, but schedule the optimization on a regular basis. Plex allows you to schedule this task on a weekly basis.

To schedule the database optimization, use the following steps:

  1. Open a Web browser and navigate to your Plex server.
  2. Log into your Plex server with an administrator account.
  3. Click the Settings icon - the wrench - in the upper-right corner of the Plex server page.
  4. On the left menu, click the Scheduled Tasks option under the Settings section.
  5. Check the Optimize database every week option.
  6. Click the Save Changes button at the bottom of the page to save your changes.
    Optimize database every week option in Plex.
    The 'Optimize database every week' option in Plex

The above steps will have Plex optimize the database on a weekly basis to help keep your Plex server running fast.

Running optimize database on-demand

When the optimize database option is run, whether from the Plex Web app or the scheduler, Plex calls its API command to optimize the database. You can also run the optimize database API command anytime to maintain your Plex server database whenever you wish.

The Plex scheduler outlined in the previous section will run the optimize database command on a weekly basis. If you would like to run the command on a different schedule, then you can call the optimize database API command from a third-party scheduler instead of using the built-in Plex scheduler.

Optimizing your Plex database is a good way to keep your Plex server running at its best. It is good practice to run this command on a weekly basis.