# Optimize Database makes Plex unresponsive

**URL:** <https://forums.plex.tv/t/optimize-database-makes-plex-unresponsive/745878>\
**Category:** Plex Media Server\
**Tags:** server-linux\
**Created:** [September 25, 2021, 1:03pm UTC](https://forums.plex.tv/t/optimize-database-makes-plex-unresponsive/745878 "2021-09-25T13:03:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Departed69](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/departed69/32/131298_2.png) [@Departed69](https://forums.plex.tv/u/Departed69)\
**Post date:** [September 25, 2021, 1:03pm UTC](https://forums.plex.tv/t/optimize-database-makes-plex-unresponsive/745878/1 "2021-09-25T13:03:32Z")

</div>

Server Version#: 1.24.3.5033

When I run an Optimize Database from the Plex UI, Plex becomes completely unresponsive, requiring a Plex server restart. I have seen several other posts and threads about this issue, but no actual fixes that apply to my situation/setup.

Including logs grabbed after an Optimize attempt and Plex restart. Any help would be greatly appreciated. Thanks!

[Plex Media Server Logs\_2021-09-25\_14-44-22.zip](https://forums.plex.tv/uploads/short-url/y5Kfg8R6i79fthZue93fJUwDYpC.zip) (4.8 MB)

---

<div class="post-metadata">

**Author:** ![Departed69](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/departed69/32/131298_2.png) [@Departed69](https://forums.plex.tv/u/Departed69)\
**Post date:** [September 26, 2021, 1:21am UTC](https://forums.plex.tv/t/optimize-database-makes-plex-unresponsive/745878/2 "2021-09-26T01:21:47Z")

</div>

@ChuckPa sorry to ping you, but I’ve seen you replying to other threads, and have been very helpful. I was hoping you could take a look into my logs and see if you can figure out what’s going on in my case. Thanks!

---

<div class="post-metadata">

**Author:** ![ChuckPa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/chuckpa/32/79710_2.png) [@ChuckPa](https://forums.plex.tv/u/ChuckPa)\
**Post date:** [September 26, 2021, 2:10am UTC](https://forums.plex.tv/t/optimize-database-makes-plex-unresponsive/745878/3 "2021-09-26T02:10:28Z")

</div>

@Departed69

Optimizing the database will suspend all other operations currently in progress because of what it’s doing.

In order to safely clean out all the empty space in the database, the process must know that nothing is in the process of using a spot about to get removed Therefore, it exclusively locks the database for it’s sole use during that time.

Most of us put our metadata (only) on SSDs so that time is further limited.

Looking at your logs is fairly routine.

I see some media deletion (files moved ?) and playback tasks.

Is there something in particular ?

---

<div class="post-metadata">

**Author:** ![Departed69](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/departed69/32/131298_2.png) [@Departed69](https://forums.plex.tv/u/Departed69)\
**Post date:** [September 26, 2021, 2:36am UTC](https://forums.plex.tv/t/optimize-database-makes-plex-unresponsive/745878/4 "2021-09-26T02:36:49Z")

</div>

Hi @ChuckPa, thanks for your response. The database is on a high speed NVMe drive.

My problem is that it never seems to recover from the Optimize operation. I eventually have to restart the Plex server, otherwise it remains unresponsive.

The first time I noticed this was when the overnight scheduled task ran an Optimize, and the next morning when I woke up, the server was not reachable. At that point I restarted it and removed the Optimize from the scheduled tasks. But again, whenever I run it manually, it never recovers.

Can I ask you this … what actual sqlite operations are being performed by the Optimize routine? Is it the same as in this link: [Repair a Corrupted Database | Plex Support](https://support.plex.tv/articles/repair-a-corrupted-database/)? If so, I could write an external script to quit Plex, run those commands, then restart the server. That might be quicker than having it done while Plex is running. Thoughts?

---

<div class="post-metadata">

**Author:** ![ChuckPa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/chuckpa/32/79710_2.png) [@ChuckPa](https://forums.plex.tv/u/ChuckPa)\
**Post date:** [September 26, 2021, 3:12am UTC](https://forums.plex.tv/t/optimize-database-makes-plex-unresponsive/745878/5 "2021-09-26T03:12:58Z")

</div>

It’s performing a `vacuum` operation.

If you want to export and re-import in a script, whatever you feel up to handling.

---

<div class="post-metadata">

**Author:** ![OttoKerner](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ottokerner/32/10079_2.png) [@OttoKerner](https://forums.plex.tv/u/OttoKerner)\
**Post date:** [September 26, 2021, 12:11pm UTC](https://forums.plex.tv/t/optimize-database-makes-plex-unresponsive/745878/6 "2021-09-26T12:11:50Z")

</div>

> [@Departed69](#):
>
> If so, I could write an external script to quit Plex, run those commands, then restart the server.

Doing it with a script is certainly quicker, but you might be missing messages about a failed repair.  
I recommend you to perform the “manual” repair procedure. Interactively, one command at a time.

---

<div class="post-metadata">

**Author:** ![vtdweller](https://avatars.discourse-cdn.com/v4/letter/v/41988e/32.png) [@vtdweller](https://forums.plex.tv/u/vtdweller)\
**Post date:** [December 1, 2021, 12:52am UTC](https://forums.plex.tv/t/optimize-database-makes-plex-unresponsive/745878/7 "2021-12-01T00:52:43Z")

</div>

I understand that the server will be unresponsive while the optimization task is being executed, but everyone seems to think that the optimization should be quick, but mine hangs for a long time and sometimes requires a docker restart. I’ve checked the logs, but can’t find where the optimization entries are.

How can I determine what’s going on with the optimization task and how to speed it up? My library is not large.

---

<div class="post-metadata">

**Author:** ![ChuckPa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/chuckpa/32/79710_2.png) [@ChuckPa](https://forums.plex.tv/u/ChuckPa)\
**Post date:** [December 1, 2021, 1:06am UTC](https://forums.plex.tv/t/optimize-database-makes-plex-unresponsive/745878/8 "2021-12-01T01:06:03Z")

</div>

The optimization is a SQLite `vacuum` operation where it removes all the empty records and writes a compacted version of itself.

My DB is only a few hundred (500) MB and , following the upgrade, that first optimize required almost 40 minutes. Your mileage will vary

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [March 1, 2022, 1:06am UTC](https://forums.plex.tv/t/optimize-database-makes-plex-unresponsive/745878/9 "2022-03-01T01:06:18Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
