# 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:** 6

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

</div>

DBRepair.sh is located in the container /config directory

So, what am I missing?

```auto
fred@omv:~$ docker exec -it plex /bin/bash
root@omv:/# s6-svc -d /var/run/service/plex
root@omv:/# /config/DBRepair.sh
Error: Unknown host. Currently supported hosts are: QNAP, Synology (DSM 6 & DSM 7), Linux Workstation/Server
/config/DBRepair.sh: 16: Error: Unknown host. Currently supported hosts are: QNAP, Synology (DSM 6 & DSM 7), Linux Workstation/Server: not found

```

---

<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:43pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/103 "2022-10-15T18:43:19Z")

</div>

I’m going to tweak it right now. I rebuilt the container a second time and got a different result.

I understand.

---

<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:53pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/104 "2022-10-15T18:53:55Z")

</div>

@frederick.grayson

Docker container test restructured a bit. It likes LSIO and PlexInc now

```auto
root@lsioplex:/# hostname
lsioplex
root@lsioplex:/# ls
app boot config defaults docker-mods home lib lib64 media opt proc run srv tmp usr
bin command data dev etc init lib32 libx32 mnt package root sbin sys transcode var
root@lsioplex:/# cd
root@lsioplex:~# ls
DBrepair.sh
root@lsioplex:~# ./DBrepair.sh 
 
 
 
      (DEVELOPMENT) Plex Media Server Database Repair Utility (Docker)
 
Select
 
  1. Check database
  2. Vacuum database
  3. Reindex database
  4. Attempt database repair
  5. Replace current database with newest usable backup copy
  6. Undo last successful action (Vacuum, Reindex, Repair, or Replace)
  7. Show logfile
  8. Exit
 
Enter choice: 

```

I can make it such that `lsio` and `plexinc` are distinctly reported but doesn’t seem to buy anything.

---

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

</div>

Thanks for the fix.

I have the menu now. Let’s see how much trouble I can get into now :-0

---

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

</div>

What symptoms are you seeing?

I can guide you

---

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

</div>

Not really having any real symptoms other than what I see as sluggishness in the Plex web interface, probably aggravated by having large libraries.

When I add movies to the directory that holds them all it takes quite a while for Plex to digest that. Meanwhile, while it is chewing on the addition operation and updating things I can’t visit other areas of the interface. I have emptied the trash, cleaned bundles, and optimised the database but this doesn’t seem to improve things.

---

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

</div>

> [@frederick.grayson](#):
>
> what I see as sluggishness in the Plex web interface, probably aggravated by having large libraries.

For sluggishness in Plex/web, presuming you have a fast enough machine -

- Repair Database
- Reindex Database

Do this because :

1. Repair performs a full export, in database logical order and writes a ‘sorted’ file where the tables are again contiguous. It then imports back and writes perfect sorted order.

2. Reindex writes fresh indexes after the import is complete

Did this on a small Syno box with a large DB and it “jumped off the table” by comparison to before the export/import

Digesting media will improve but is still dependent on several other factors.

---

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

</div>

Thanks for the tips, I’ll try them.

Seems snappier moving around the interface. Adding new media seems the same - slow to complete.

Processor:

Intel(R) Xeon(R) CPU E3-1230 V2 @ 3.30GHz  
16GB of RAM

Movie database is 875247K (no video preview thumbnails), 38410 movies.

---

<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, 8:45pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/111 "2022-10-15T20:45:19Z")

</div>

with

[https://www.cpubenchmark.net/cpu.php?cpu=Intel+Xeon+E3-1230+V2+%40+3.30GHz&id=1189](https://www.cpubenchmark.net/cpu.php?cpu=Intel+Xeon+E3-1230+V2+%40+3.30GHz&id=1189)

that’s about 3/4 of the speed of an i7-7700.

38,000 movies needs more RAM.

Recommend 64 GB.

Try some searches to confirm

---

<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, 8:51pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/112 "2022-10-15T20:51:25Z")

</div>

Thanks for the input. I’ll see if I can find some more RAM.

---

<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, 8:53pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/113 "2022-10-15T20:53:10Z")

</div>

You’ll still be bound by the thread speed as it digests the file but RAM allows more of the DB to be in the kernel I/O buffers – which adding media is the hardest on; DB and disk i/o

---

<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, 9:29pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/114 "2022-10-15T21:29:13Z")

</div>

Thanks. Looking into it further, the MB maxes out at 32GB of RAM. Likely not worth adding another 16GB. I can live with it as is 🙂

---

<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 20, 2022, 6:39pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/117 "2022-10-20T18:39:27Z")

</div>

@flow

Can you see this?

> **[Releases · ChuckPa/PlexDBRepair](https://github.com/ChuckPa/PlexDBRepair/releases)**
>
> Database repair utility for Plex Media Server databases - ChuckPa/PlexDBRepair

---

<div class="post-metadata">

**Author:** ![r\_schumacher\_mail\_gmail\_com](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@r\_schumacher\_mail\_gmail\_com](https://forums.plex.tv/u/r_schumacher_mail_gmail_com)\
**Post date:** [October 21, 2022, 6:22am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/119 "2022-10-21T06:22:46Z")

</div>

How do i run it on Unraid? Im new to commands

---

<div class="post-metadata">

**Author:** ![Sophon0](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@Sophon0](https://forums.plex.tv/u/Sophon0)\
**Post date:** [November 3, 2022, 1:55am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/120 "2022-11-03T01:55:17Z")

</div>

I cloned the repo and tried to run the script but it’s failing for me:

```auto
root@plex:~/PlexDBRepair# ./DBRepair.sh
./DBRepair.sh: 348: Syntax error: "fi" unexpected (expecting ")")

```

I’m running it in a proxmox LXC container:

```auto
root@plex:~/PlexDBRepair# uname -a
Linux plex 5.15.39-3-pve #2 SMP PVE 5.15.39-3 (Wed, 27 Jul 2022 13:45:39 +0200) x86_64 x86_64 x86_64 GNU/Linux

```

Any idea how to fix this? 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:** [November 3, 2022, 2:14am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/121 "2022-11-03T02:14:07Z")

</div>

One of these days, I’ll learn to type.

🙄

Stand by please.

EDIT: Corrected. v0.3.3 (rerelease)

> **[Releases · ChuckPa/PlexDBRepair](https://github.com/ChuckPa/PlexDBRepair/releases)**
>
> Database repair utility for Plex Media Server databases - ChuckPa/PlexDBRepair

Cloning the repo is really counter productive.  
Using the ‘releases’ URL will always get you latest.

---

<div class="post-metadata">

**Author:** ![Mitzsch](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mitzsch/32/308163_2.png) [@Mitzsch](https://forums.plex.tv/u/Mitzsch)\
**Post date:** [November 6, 2022, 10:35am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/122 "2022-11-06T10:35:16Z")

</div>

This tool is awesome!

I have just found a case where it did not work. On my main server (with override.conf) the tool would do nothing when executed - just a blinking cursor - no menu - no nothing. I manually changed the bits inside the tool to point to the appdata/database location and then it worked. Maybe you could take a look at the override recognition logic inside your tool again? 🙂

---

<div class="post-metadata">

**Author:** ![esilberberg](https://avatars.discourse-cdn.com/v4/letter/e/b5ac83/32.png) [@esilberberg](https://forums.plex.tv/u/esilberberg)\
**Post date:** [November 29, 2022, 3:52pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/123 "2022-11-29T15:52:10Z")

</div>

> [@jasonsansone](#):
>
> your changes won’t have any lasting effect.

Could that be a used as a good thing? Test the changes using plex provided sqlite tool for the pragma change (after backup of course.)  
Then implement permanent change using the sed swap?

---

<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:** [November 29, 2022, 4:20pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/124 "2022-11-29T16:20:55Z")

</div>

> [@esilberberg](#):
>
> Could that be a used as a good thing? Test the changes using plex provided sqlite tool for the pragma change (after backup of course.)  
> Then implement permanent change using the sed swap?

sed is only going to let you change cache\_size. The other PRAGMAS are established on the creation of a database connection and a binary edit isn’t possible for those.

---

<div class="post-metadata">

**Author:** ![r\_schumacher\_mail\_gmail\_com](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@r\_schumacher\_mail\_gmail\_com](https://forums.plex.tv/u/r_schumacher_mail_gmail_com)\
**Post date:** [December 1, 2022, 12:27pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/125 "2022-12-01T12:27:03Z")

</div>

could someone explaine to me how to use this tool with unraid and Docker.  
I put the file in the folder of my PMS but what commands do i have to execute?

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

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