# Suggested SQLite3 DB Optimizations

**URL:** https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749
**Category:** Plex Media Server
**Tags:** server-linux
**Created:** [May 29, 2022, 3:20am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749 "2022-05-29T03:20:42Z")
**Posts on this page:** 20
**Page:** 5

<div class="post-metadata">

### Author: ![shark2k](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/shark2k/32/305908_2.png) [@shark2k](https://forums.plex.tv/u/shark2k)
#### Post date: [October 14, 2022, 12:30am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/82 "2022-10-14T00:30:06Z")

</div>

Thanks Chuck. Didn’t notice that the post had been edited. Sorry for not looking for that before asking the question 🫤.

-Shark2k

---

<div class="post-metadata">

### Author: ![Tangs](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/tangs/32/316974_2.png) [@Tangs](https://forums.plex.tv/u/Tangs)
#### Post date: [October 14, 2022, 6:31pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/83 "2022-10-14T18:31:27Z")

</div>

Because I don’t want to make mistakes, could you help me anderstand each step?

I downloaded your script and paste it to C:

Now:

1. I turn off PMS
2. Then run the script  
**3. How do I repair the DB?**  
**4. How do I REINDEX?**
3. I’ll restart PMS

---

<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: [October 14, 2022, 6:47pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/84 "2022-10-14T18:47:54Z")

</div>

> [@Tangs](#):
>
> I downloaded your script and paste it to C:

This is not for Windows. It is only for Linux-based hosts.

---

<div class="post-metadata">

### Author: ![jasonsansone](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/jasonsansone/32/291100_2.png) [@jasonsansone](https://forums.plex.tv/u/jasonsansone)
#### Post date: [October 14, 2022, 6:48pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/85 "2022-10-14T18:48:22Z")

</div>

The script will present those options clearly.

Edit: wasn’t paying attention to OS.

---

<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: [October 14, 2022, 6:53pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/86 "2022-10-14T18:53:46Z")

</div>

To all who might find this useful (or are curious) 😈

It will detect the OS and configure itself to the Plex standard for that OS.  
On Redhat & Debian Linux systems, it will attempt to follow Override.conf (if simple)

 ![Screenshot from 2022-10-14 14-52-53](https://global.discourse-cdn.com/plex/original/4X/f/3/e/f3e47037bba4c6dbb7334202d33ae31544fdec69.png)

Supported platforms are:

1. Mainstream Linux platforms (RPM & DEB)
2. QNAP (QTS/QuTS 5+), Synology (DSM 6 & 7), ASUSTOR, Netgear
3. Docker (s6-exec)
4. Full LXC which presents as a standard RPM/DEB host

---

<div class="post-metadata">

### Author: ![jasonsansone](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/jasonsansone/32/291100_2.png) [@jasonsansone](https://forums.plex.tv/u/jasonsansone)
#### Post date: [October 14, 2022, 7:10pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/87 "2022-10-14T19:10:40Z")

</div>

Why not just build this functionality into the binary and make it a butler task so it works across all OS and even the non-power users will benefit? This should probably be part of the existing “optimize” functionality.

---

<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: [October 14, 2022, 7:13pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/88 "2022-10-14T19:13:17Z")

</div>

Because you can’t operate on the DB while PMS has the DB open.

**ALSO**

I’m doing this to support those cases where the DB is corrupted and PMS won’t start.

---

<div class="post-metadata">

### Author: ![jasonsansone](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/jasonsansone/32/291100_2.png) [@jasonsansone](https://forums.plex.tv/u/jasonsansone)
#### Post date: [October 14, 2022, 7:15pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/89 "2022-10-14T19:15:08Z")

</div>

Sure, but it can occur on start up or shutdown ie upgrades. That is exactly what I have scripted is to run after every upgrade but before restarting Plex. The binary executable can operate with the sqlite connection closed, hence the ability to make calls to Plex SQLite.

---

<div class="post-metadata">

### Author: ![Tangs](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/tangs/32/316974_2.png) [@Tangs](https://forums.plex.tv/u/Tangs)
#### Post date: [October 14, 2022, 7:17pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/90 "2022-10-14T19:17:10Z")

</div>

Arf 🙂  
That would be great if it was possible to run it in other OS like … windows 😌

---

<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: [October 14, 2022, 7:24pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/91 "2022-10-14T19:24:15Z")

</div>

> [@jasonsansone](#):
>
> Sure, but it can occur on start up or shutdown ie upgrades. That is exactly what I have scripted is to run after every upgrade but before restarting Plex. The binary executable can operate with the sqlite connection closed, hence the ability to make calls to Plex SQLite.

I hear what you’re saying but this is not the venue for that discussion.

Please consider what I’ve done as PoC and the First-Aid Kit.

It addresses the problem in 99.9% of the cases.  
(No need for a vaccine to be developed for a paper cut – analogy)

Please remember I’m support and independent of what Product & Engineering might decide.

---

<div class="post-metadata">

### Author: ![Tangs](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/tangs/32/316974_2.png) [@Tangs](https://forums.plex.tv/u/Tangs)
#### Post date: [October 14, 2022, 7:32pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/92 "2022-10-14T19:32:21Z")

</div>

So without using your tool, I could still go through this:  
[https://support.plex.tv/articles/repair-a-corrupted-database/](https://support.plex.tv/articles/repair-a-corrupted-database/)  
and it may help?

---

<div class="post-metadata">

### Author: ![frederick.grayson](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/frederick.grayson/32/14914_2.png) [@frederick.grayson](https://forums.plex.tv/u/frederick.grayson)
#### Post date: [October 14, 2022, 9:23pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/93 "2022-10-14T21:23:36Z")

</div>

Is there an conspicuous link to get a copy of this script?

---

<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: [October 14, 2022, 10:06pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/94 "2022-10-14T22:06:06Z")

</div>

@frederick.grayson

It’s in this thread… You only needed to scroll back.

> [@Suggested SQLite3 DB Optimizations](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/69):
>
> Here is my tool. Stop PMS Run as root If you want the most expedient, I recommend actions: Check Repair Reindex If you want to examine the individual facets, Check – ls -la the database sizes before starting Vacuum – Now ls -la of the databases again Reindex – One last check Feel free to check the DB sizes between each step. The only conflict possible is if PMS is running and you attempt to use the tool AFTER PMS starts. This tool only checks for PMS at first startup so be careful…

---

<div class="post-metadata">

### Author: ![Gloppie](https://avatars.discourse-cdn.com/v4/letter/g/74df32/32.png) [@Gloppie](https://forums.plex.tv/u/Gloppie)
#### Post date: [October 14, 2022, 10:06pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/95 "2022-10-14T22:06:25Z")

</div>

It worked on Gentoo 😉

---

<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: [October 14, 2022, 10:11pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/96 "2022-10-14T22:11:44Z")

</div>

> [@Tangs](#):
>
> So without using your tool, I could still go through this:  
> [https://support.plex.tv/articles/repair-a-corrupted-database/](https://support.plex.tv/articles/repair-a-corrupted-database/)  
> and it may help?

Without using my tool, you perform all the steps by hand.

I give you more ways to repair the DB than the support article with simple menu choices.

---

<div class="post-metadata">

### Author: ![Tangs](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/tangs/32/316974_2.png) [@Tangs](https://forums.plex.tv/u/Tangs)
#### Post date: [October 15, 2022, 7:38am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/97 "2022-10-15T07:38:18Z")

</div>

Thank you 🙂  
As a windows user that seems to be my only solution, or do you plan to make it for this OS too ?

---

<div class="post-metadata">

### Author: ![frederick.grayson](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/frederick.grayson/32/14914_2.png) [@frederick.grayson](https://forums.plex.tv/u/frederick.grayson)
#### Post date: [October 15, 2022, 3:54pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/98 "2022-10-15T15:54:34Z")

</div>

Thanks for the location of the link to the file.

However, unless I am mistaken, the tool is not compatible with the [linuxserver.io](http://linuxserver.io) docker image as there is no file named **plex\_service.sh** included in that image, and perhaps other needed files too.

---

<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: [October 15, 2022, 4:58pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/99 "2022-10-15T16:58:04Z")

</div>

@frederick.grayson

I don’t keep track of all the docker images as there are too many

If you’re going to use Docker, it is suggested you know how to control it.

```auto
cd /var/run/s6/services
s6-svc -d plex

```

-or-

```auto
s6-svc -d /var/run/service/plex

```

Everything else needed is there. I already worked with a user who uses [Linuxserver.io](http://Linuxserver.io).

~~When I get a chance, I’ll see if i can add “[Linuxserver.io](http://Linuxserver.io)” as a host type.~~

I currently have the official Plex docker image .

you all know I’m not fond of docker due to all the variations. This is a prime example

**EDIT: No changes to existing scripting is required to support [Linuxserver.io](http://Linuxserver.io) Docker image. Default location for PMS is unchanged.**

---

<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: [October 15, 2022, 5:13pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/100 "2022-10-15T17:13:30Z")

</div>

> [@Tangs](#):
>
> Thank you 🙂  
> As a windows user that seems to be my only solution, or do you plan to make it for this OS too ?

This script is a personal project of mine. It’s not the slightest bit official.  
I don’t have any windows computers in my house.

That as basis, I have no idea how PMS runs on Windows platforms.

Does my script even run on Windows?  
From what I remember , BAT files at just that – batty as heck.  
and Cygwin stuff isn’t compatible because of all the variations.

If that’s changed, maybe it can be developed but working that out and making it happen are a separate discussion.

---

<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: [October 15, 2022, 6:40pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/101 "2022-10-15T18:40:52Z")

</div>

@frederick.grayson

I see something else I should adjust. I understand your complaint.

Stand by

[Previous page](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749.md?page=4)

[Next page](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749.md?page=6)
