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
Using the troubleshooting option
Scheduling optimize database in Plex
Running optimize database on-demand

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. Log into your Plex server as an administrator, and then click the Settings - the wrench - link in the upper-right corner of the Plex server page.
    Plex Settings Icon.
    The 'Plex Settings' icon
  2. On the left menu, click the Troubleshooting option under the Manage section.
    Plex Troubleshooting Option.
    The 'Plex Troubleshooting' option
  3. 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
  4. 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 maintenance task on a weekly basis.

To schedule the database optimization, use the following steps:

  1. Log into your Plex server as an administrator, and then click the Settings - the wrench - link in the upper-right corner of the Plex server page.
    Plex Settings Icon.
    The 'Plex Settings' icon
  2. On the left menu, click the Scheduled Tasks option under the Settings section.
    Plex Scheduled Tasks Option.
    The 'Plex Scheduled Tasks' option
  3. Check the Optimize database every week option. 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.

If needed, you can manually run the optimize database task using the Plex API.

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.

Subscribe
Display