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

<div class="post-metadata">

### Author: ![silenceheaven](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/silenceheaven/32/107596_2.png) [@silenceheaven](https://forums.plex.tv/u/silenceheaven)
#### Post date: [September 29, 2022, 4:07pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/42 "2022-09-29T16:07:42Z")

</div>

Gotcha, use “Plex SQLite” instead 👍

---

<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: [September 29, 2022, 4:19pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/43 "2022-09-29T16:19:55Z")

</div>

> [@silenceheaven](#):
>
> You could use [https://sqlitebrowser.org/](https://sqlitebrowser.org/) to modify the database in Windows without using the command line.

[“Plex Media Server includes its own SQLite command line interpreter.”](https://support.plex.tv/articles/repair-a-corrupted-database/)

You need to use the provided Plex SQLite to make any modifications to a Plex database.

> [@DeBoet](#):
>
> I’ve tried the sqlitebrowser, changing the PRAGMA values mentioned above is impossible, it refuses to save and returns to default values when I re-open the program.

Correct. Most of the PRAGMA’s are established at the time of the database connection. Unless you modify the binary, to the limited ability we can, your changes won’t have any lasting effect.

---

<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: [September 29, 2022, 4:27pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/44 "2022-09-29T16:27:57Z")

</div>

[Sample script code here.](https://pastebin.com/mQMRgRR4)

[You could also run this in cron to regularly reduce the WAL to keep it from getting bloated.](https://pastebin.com/isgXfxNv)

---

<div class="post-metadata">

### Author: ![DeBoet](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/deboet/32/160675_2.png) [@DeBoet](https://forums.plex.tv/u/DeBoet)
#### Post date: [September 29, 2022, 4:28pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/45 "2022-09-29T16:28:55Z")

</div>

I managed to adapt the cache\_size values in the binary, that was about the easiest.

As for the SQLite, changing any of the values there doesn’t work either, they just reset back to their defaults. I couldn’t even adapt the cache\_size through there as it stuck to 1024.

But perhaps we’ll have these slightly better tweaks added to plex within the next 3 decades, so that’s nice.

---

<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: [September 29, 2022, 4:31pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/46 "2022-09-29T16:31:39Z")

</div>

> [@DeBoet](#):
>
> But perhaps we’ll have these slightly better tweaks added to plex within the next 3 decades, so that’s nice.

Cache size is managed by the connection. For changes to persist, you need to make them to the binary with sed. Page size can be changed with the code samples above.

---

<div class="post-metadata">

### Author: ![DeBoet](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/deboet/32/160675_2.png) [@DeBoet](https://forums.plex.tv/u/DeBoet)
#### Post date: [September 29, 2022, 4:34pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/47 "2022-09-29T16:34:20Z")

</div>

> [@DeBoet](#):
>
> I managed to adapt the cache\_size values in the binary, that was about the easiest.

Those are done 🙂 more things like locking\_mode and mmap\_size were ones I wanted to adapt, guess that won’t be happening.

EDIT:

This happens if I edit the page\_size through the sql tool:  
[https://www.boetservers.nl/index.php/s/icN7oxLfqBGfamD/download/mstsc\_eYyIcxEy37.png](https://www.boetservers.nl/index.php/s/icN7oxLfqBGfamD/download/mstsc_eYyIcxEy37.png)

That means it did f all right?

---

<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: [September 29, 2022, 4:40pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/48 "2022-09-29T16:40:40Z")

</div>

You didn’t read the code snippet I provided. The pagesize only changes when you re-write the entire database, which will occur on a vacuum after the WAL is turned off.

---

<div class="post-metadata">

### Author: ![silenceheaven](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/silenceheaven/32/107596_2.png) [@silenceheaven](https://forums.plex.tv/u/silenceheaven)
#### Post date: [September 29, 2022, 4:41pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/49 "2022-09-29T16:41:19Z")

</div>

The script I posted is for executing the binary modifications in a Plex container.

Also your script has only `sed -i.bak -e 's/cache_size=2000/cache_size=9999/' '/usr/lib/plexmediaserver/Plex Media Server'` but is missing `sed -i.bak -e 's/cache_size = 4096/cache_size = 9999/' '/usr/lib/plexmediaserver/Plex Media Server'` to account for the spaces between the equal sign.

---

<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: [September 29, 2022, 4:44pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/50 "2022-09-29T16:44:41Z")

</div>

It isn’t missing. [The second line is related to iTunes only](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/32). It is intentionally omitted since it is unnecessary.

---

<div class="post-metadata">

### Author: ![silenceheaven](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/silenceheaven/32/107596_2.png) [@silenceheaven](https://forums.plex.tv/u/silenceheaven)
#### Post date: [September 29, 2022, 4:50pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/51 "2022-09-29T16:50:30Z")

</div>

Ah I apologize! I will update the script I posted!

Thank you!

---

<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: [September 29, 2022, 4:51pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/52 "2022-09-29T16:51:25Z")

</div>

You don’t “have” to change it, just letting you know it doesn’t provide any meaningful benefit in the scope of this thread. No apologies necessary!

---

<div class="post-metadata">

### Author: ![silenceheaven](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/silenceheaven/32/107596_2.png) [@silenceheaven](https://forums.plex.tv/u/silenceheaven)
#### Post date: [September 29, 2022, 5:08pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/53 "2022-09-29T17:08:45Z")

</div>

No worries, I still adjusted the script to do the database modifications and removed the iTunes part.

Hopefully someone finds it useful!

---

<div class="post-metadata">

### Author: ![DeBoet](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/deboet/32/160675_2.png) [@DeBoet](https://forums.plex.tv/u/DeBoet)
#### Post date: [September 29, 2022, 6:35pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/54 "2022-09-29T18:35:03Z")

</div>

Ah, my mistake! I have since been able to modify the page\_size sucessfully, indeed the rebuild was the missing link and my experience here failed me.

so I managed to adapt page\_size (using your script adapted to windows) and cache\_size within the binary using an editor.

Were the others useful in any way? For example temp\_store can’t be set to 2 (added them to the script or changing them in the sql tool both reset/never changed to 0), and the mmap\_size really likes the value of 0 as well.

As for the performance difference, outside of a likely case of placebo effect it does feel snappier and seems to load up the categories faster (movies/tv series). And whatever the case I’d love plex to eat all the RAM I have any way if it makes it go a bit faster.

---

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

</div>

I’m new to this thread but I may be really interested in it.  
What you propose here is to have a better experience in Plex client while scrolling larges librairies ?

Having Plex server install on a windows 10 machine is the way to go with what you are working on ?

I have about 6000 movies and 1200 tv shows, with a good numbers of collections pinned on my homescreen and using an Nvidia Shield to browse everything can be something slow.

---

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

</div>

Yeah, these are relevant for Windows.

A handful of us have been using larger database page sizes forever, and would claim - anecdotally - that it helps, like, a bit. I don’t think anybody has bothered to actually measure and compare scientifically.

Increasing the database page size will certainly not hurt.

Also be sure to put the plex database and other metadata on the fastest storage you can.

When browsing libraries, another ~slow operation is poster generation. Plex can be a bit silly about poster image caching. Having a reasonably fast server CPU and very fast storage for all of the metadata is very helpful.

---

<div class="post-metadata">

### Author: ![anon5074910](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@anon5074910](https://forums.plex.tv/u/anon5074910)
#### Post date: [October 1, 2022, 10:44pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/57 "2022-10-01T22:44:24Z")

</div>

I’d also add to not forget about network between your client (shield) and server (windows 10).

A slow(er) connection here could have an impact on the plex app fetching the artwork from the server when quickly scrolling. When I connected via client using a wired connection rather than wifi there was a noticeable boost in the plex app when browsing large libraries.

Just another consideration so said I’d mention it.

---

<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 11, 2022, 1:49pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/58 "2022-10-11T13:49:30Z")

</div>

Should i use this script in a powershell?

1. service plexmediaserver stop

2. “/usr/lib/plexmediaserver/Plex SQLite” “/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db” “PRAGMA page\_size=65536” “PRAGMA journal\_mode=DELETE” “VACUUM” “PRAGMA journal\_mode=WAL” “PRAGMA optimize”

3. “/usr/lib/plexmediaserver/Plex SQLite” “/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.blobs.db” “PRAGMA page\_size=65536” “PRAGMA journal\_mode=DELETE” “VACUUM” “PRAGMA journal\_mode=WAL” “PRAGMA optimize”

4. sed -i.bak -e ‘s/cache\_size=2000/cache\_size=9999/’ ‘/usr/lib/plexmediaserver/Plex Media Server’

5. service plexmediaserver start

Then i will increase the cache allowed for plex posters?

---

<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 11, 2022, 2:46pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/59 "2022-10-11T14:46:24Z")

</div>

Pretty sure you need to set step 4 after you stop the service, but before step 2, and 3.

@ChuckPa does this violate plex’s licensing?

---

<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 11, 2022, 3:01pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/60 "2022-10-11T15:01:09Z")

</div>

Sed is modifying the binary. The order doesn’t matter. No need to move Step 4 to a different position.

A plain reading of the license would confirm that [these actions violate Paragraph 2](https://www.plex.tv/about/privacy-legal/plex-terms-of-service/)… of course most software licenses are written in a manner that the license is violated for using the software when the sky is blue, there is oxygen in the atmosphere, or the earth has a gravitational field.

---

<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 11, 2022, 3:02pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/61 "2022-10-11T15:02:27Z")

</div>

OK, good to know about the order.

I only ask about licensing because I package this for Gentoo in my overlay, and I want to stay in the good graces of Plex.

@jasonsansone Thank you by the way for sharing this wonderful improvement.

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

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