# Optimize Database crashing Plex

**URL:** <https://forums.plex.tv/t/optimize-database-crashing-plex/717432>\
**Category:** Plex Media Server\
**Tags:** server-windows\
**Created:** [May 23, 2021, 2:50pm UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432 "2021-05-23T14:50:37Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zer0Squared](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/zer0squared/32/23237_2.png) [@Zer0Squared](https://forums.plex.tv/u/Zer0Squared)\
**Post date:** [May 23, 2021, 2:50pm UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432/1 "2021-05-23T14:50:37Z")

</div>

Server Version#: 1.22.3.4523  
Player Version#: 4.57.2

I’ve seen a couple of Topics about this issue but I can’t tell what exactly the solution is.  
My server is slow to start playing media, it feels laggy and the Console window is constantly showing that it’s updating metadata for things it’s already tagged.

Anyway, my main problem is that any time I try to Optimize the DB in Plex, it immediately kills any use of the server. Anything playing will stop, remote connections drop, if you _are_ on the home page, nothing will be able to start playing, etc.

When this happened previously, I stopped Plex from the system try and when I check in Task Manager, everything had stopped except for Plex Media Server.exe - which was still very slowly doing something. Was it actually optimizing or just hanging? I’m not sure where to look. I have a pretty healthy library so I’m guessing it could take a while?

I used to be able to do this with no issue but I’m guess my DB is corrupted so I’m looking for a way to maybe externally repair/optimize it. I’ve seen the old topic of:  
[https://support.plex.tv/articles/201100678-repair-a-corrupt-database/](https://support.plex.tv/articles/201100678-repair-a-corrupt-database/)

…but everywhere I’m reading now says that you must use the sqlite that is built into Plex. I can’t find a Windows versions of the instructions and I’m sure there has to be an easy way to do this…or maybe there’s a way to optimize it outside of Plex? Someone said they did it externally once and it worked but they didn’t mention how. ☹

---

<div class="post-metadata">

**Author:** ![hthighway](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/hthighway/32/82003_2.png) [@hthighway](https://forums.plex.tv/u/hthighway)\
**Post date:** [May 23, 2021, 3:01pm UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432/2 "2021-05-23T15:01:37Z")

</div>

take a look at this thread -

> [@Can no longer update library database with sqlite3](https://forums.plex.tv/t/can-no-longer-update-library-database-with-sqlite3/701405/19):
>
> I’ve been using sqlite3.exe with PowerShell on Windows to update my Plex DB for a while now and it stopped working after a recent update. I found this post and based on @Volts comment I was able to figure out how to get it working again using the Plex EXE. Here is a basic command format I use on Windows and with PowerShell in case anyone is interested: $PlexDB = “C:\Users\PLEX\AppData\Local\Plex Media Server\Plug-in Support\Databases\com.plexapp.plugins.library.db” $PlexEXE = “C:\Program Fi…

Not sure why Plex is taking forever to update their help docs

---

<div class="post-metadata">

**Author:** ![Zer0Squared](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/zer0squared/32/23237_2.png) [@Zer0Squared](https://forums.plex.tv/u/Zer0Squared)\
**Post date:** [May 26, 2021, 4:58pm UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432/3 "2021-05-26T16:58:51Z")

</div>

I was able to find some instructions that “worked” in so much as, after I ran the Restore DB commands using the PMS -sqlite format, it seemed to work.

PMS just seems so delicate right now to me. I can do everything just fine EXCEPT the Optimize DB command. It instantly kills the service. But as mentioned, when I Exit using the systray icon, everything closes _except_ PMS.exe but I don’t know if it’s actually doing anything. I’ve let it run for a while hoping it would close when finished but it never did.

I’m happy to try Optimize again and send someone some log files, if that’ll help but this is driving me crazy. ☹

---

<div class="post-metadata">

**Author:** ![Zer0Squared](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/zer0squared/32/23237_2.png) [@Zer0Squared](https://forums.plex.tv/u/Zer0Squared)\
**Post date:** [June 5, 2021, 5:54pm UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432/4 "2021-06-05T17:54:49Z")

</div>

Bump. This is still an issue for me - even though I have used the steps to fix a corrupted database several times on different days when it seems extra slow, I can’t even find documentation that says it also optimizes it when it does so.

Does anyone know?

Can we get a way to Optimize the DB from _outside_ of Plex?  
(probably not since they added their own sqlite and now you can’t do anything from outside)

---

<div class="post-metadata">

**Author:** ![Zer0Squared](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/zer0squared/32/23237_2.png) [@Zer0Squared](https://forums.plex.tv/u/Zer0Squared)\
**Post date:** [June 17, 2021, 1:03pm UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432/5 "2021-06-17T13:03:07Z")

</div>

Bump.  
Still going on.

---

<div class="post-metadata">

**Author:** ![Volts](https://avatars.discourse-cdn.com/v4/letter/v/a5b964/32.png) [@Volts](https://forums.plex.tv/u/Volts)\
**Post date:** [June 17, 2021, 4:54pm UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432/6 "2021-06-17T16:54:04Z")

</div>

The [repair a corrupted database](https://support.plex.tv/articles/repair-a-corrupted-database/) instructions have been updated, but the fundamentals are the same.

It’s normal for `Optimize` to pause Plex activity while it completes. But obviously it should complete …

How big is your database? How long have you waited?

---

<div class="post-metadata">

**Author:** ![JuiceWSA](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/juicewsa/32/12253_2.png) [@JuiceWSA](https://forums.plex.tv/u/JuiceWSA)\
**Post date:** [June 17, 2021, 5:05pm UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432/7 "2021-06-17T17:05:50Z")

</div>

> [@Volts](#):
>
> How big is your database?

Mine is big enough that I stopped waiting for (what seems like) days to find out.

6500+ Movies  
600+ Shows - 14,000+ Episodes  
With Preview and Chapter Thumbs for both.

Optimize completes in - a minute (that seems long - probably less)?

If you have any tips on database inspection - I’m all ears (and nose).

---

<div class="post-metadata">

**Author:** ![Zer0Squared](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/zer0squared/32/23237_2.png) [@Zer0Squared](https://forums.plex.tv/u/Zer0Squared)\
**Post date:** [June 17, 2021, 5:13pm UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432/8 "2021-06-17T17:13:26Z")

</div>

My library isn’t as big as Juice’s, but yea - I used to Optimize it all the time myself and it never took that long to complete - and it didn’t kill any remote streams while it was doing it. It just started recently with the last (next to last now?) build.

Once it “crashes” every other Plex process in Task Manager except for PMS.exe, I’ve let it run for quite a while but it was taking forever and the resources never really moved.

Every now and then I would run through the Repair steps, hoping it was optimizing while doing so, but I’m not sure if it does. I do see a new command on that page now that says “_The above command will reassemble your database with all the valid data it can find in your file._” Is that optimizing it? If so, I’ll try it.

---

<div class="post-metadata">

**Author:** ![Zer0Squared](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/zer0squared/32/23237_2.png) [@Zer0Squared](https://forums.plex.tv/u/Zer0Squared)\
**Post date:** [June 17, 2021, 5:25pm UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432/9 "2021-06-17T17:25:53Z")

</div>

**UPDATE** : Whoa - ok. I stopped the server and ran this command on the db from the [Repair DB link](https://support.plex.tv/articles/repair-a-corrupted-database/) with updated commands.

“C:\Program Files (x86)\Plex\Plex Media Server\Plex SQLite.exe” com.plexapp.plugins.library.db “.output recover.out” “.recover”

After that, I shrugged and clicked Optimize…and it completed! And it only took about a minute. So - I have no idea what happened, but this seemed to work for me. So happy.

**UPDATE** (_3 Days Later_): So, on a whim, after watching several movies and shows, I decided I would give using the Optimize Database click one more shot since it ‘seemed’ to work last time. And…it DID! And, it took it about a minute or two to complete.

---

<div class="post-metadata">

**Author:** ![JuiceWSA](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/juicewsa/32/12253_2.png) [@JuiceWSA](https://forums.plex.tv/u/JuiceWSA)\
**Post date:** [June 17, 2021, 5:26pm UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432/10 "2021-06-17T17:26:34Z")

</div>

WoooHoooo!

---

<div class="post-metadata">

**Author:** ![Volts](https://avatars.discourse-cdn.com/v4/letter/v/a5b964/32.png) [@Volts](https://forums.plex.tv/u/Volts)\
**Post date:** [June 17, 2021, 5:27pm UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432/11 "2021-06-17T17:27:52Z")

</div>

The old database repair steps do a really simple “dump” and “read”. It means there’s no old junk in the database files, but I don’t think it’s exactly the same as what Plex does internally for `Optimize`.

The SQLite `.recover` command is also very unlikely to do an `Optimize`.

---

<div class="post-metadata">

**Author:** ![Zer0Squared](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/zer0squared/32/23237_2.png) [@Zer0Squared](https://forums.plex.tv/u/Zer0Squared)\
**Post date:** [June 17, 2021, 5:28pm UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432/12 "2021-06-17T17:28:50Z")

</div>

Fair enough, but I ran Optimize a couple nights ago and it crashed. I ran that command and now Optimize is working as intended. It may be a coincidence but I’ll take the win. 🙂

---

<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:** [June 17, 2021, 5:29pm UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432/13 "2021-06-17T17:29:59Z")

</div>

A freshly imported DB is already optimized.

Optimization is part of the nightly server maintenance, btw.  
There is actually no need to trigger it manually, except after extensive changes like massive numbers of imports or deletions.

---

<div class="post-metadata">

**Author:** ![Volts](https://avatars.discourse-cdn.com/v4/letter/v/a5b964/32.png) [@Volts](https://forums.plex.tv/u/Volts)\
**Post date:** [June 17, 2021, 5:30pm UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432/14 "2021-06-17T17:30:37Z")

</div>

The “dump” and “read” can certainly help if there’s anything invalid or any broken references in the file.

---

<div class="post-metadata">

**Author:** ![Zer0Squared](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/zer0squared/32/23237_2.png) [@Zer0Squared](https://forums.plex.tv/u/Zer0Squared)\
**Post date:** [June 17, 2021, 5:32pm UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432/15 "2021-06-17T17:32:21Z")

</div>

Yes, I had just removed a fairly large Photo library so that’s why I was trying to run it. And it’s not part of MY nightly cycle as I have that box unchecked because of crashing. 🙂

---

<div class="post-metadata">

**Author:** ![JuiceWSA](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/juicewsa/32/12253_2.png) [@JuiceWSA](https://forums.plex.tv/u/JuiceWSA)\
**Post date:** [June 17, 2021, 5:33pm UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432/16 "2021-06-17T17:33:12Z")

</div>

> [@OttoKerner](#):
>
> except after extensive changes like massive numbers of imports or deletions.

Describe:  
“Massive”

I often Move 200 items around to balance storage loading across 6HDDs.  
I optimize after that.  
'Cause I can.

I also Optimize - when I’m bored - 'cause I can and 'cause my Database runs on an HDD - and when I read ‘operates as quickly as possible’ I was sold. Seems to be fast enough for us - almost instant is pretty quick.

---

<div class="post-metadata">

**Author:** ![Volts](https://avatars.discourse-cdn.com/v4/letter/v/a5b964/32.png) [@Volts](https://forums.plex.tv/u/Volts)\
**Post date:** [June 17, 2021, 6:39pm UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432/17 "2021-06-17T18:39:35Z")

</div>

> [@OttoKerner](#):
>
> A freshly imported DB is already optimized.

I agree that a freshly imported DB is stored efficiently on disk. There’s no empty space in the database from deleted records, etc. That’s similar to the results of a DB `vacuum`, which I believe Plex performs during `Optimize`.

`Optimize` also rebuilds the full-text indexes, which isn’t done by a dump/read or by `.recover`.

I don’t know what the other “database fix-ups” it does are.

---

<div class="post-metadata">

**Author:** ![bhootz](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/bhootz/32/14339_2.png) [@bhootz](https://forums.plex.tv/u/bhootz)\
**Post date:** [August 15, 2021, 7:56am UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432/18 "2021-08-15T07:56:16Z")

</div>

So if it part of the nightly maintenance, then manual triggering should be very smooth instead of taking long and being unresponsive.  
Running my server on unraid and having server freeze/unresponsive. Only way to fix it is restarting the docker image.

---

<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:** [November 13, 2021, 7:56am UTC](https://forums.plex.tv/t/optimize-database-crashing-plex/717432/19 "2021-11-13T07:56:34Z")

</div>

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