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

<div class="post-metadata">

**Author:** ![chaberman43](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@chaberman43](https://forums.plex.tv/u/chaberman43)\
**Post date:** [December 14, 2022, 5:19pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/126 "2022-12-14T17:19:01Z")

</div>

I was reading through all this and went to make the recommended change to 4096 and I see it’s already set.

I suppose this means plex’s engineering team has already implemented at least some of these improvements? I hadn’t enabled this previously.

---

<div class="post-metadata">

**Author:** ![chaberman43](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@chaberman43](https://forums.plex.tv/u/chaberman43)\
**Post date:** [December 14, 2022, 5:24pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/127 "2022-12-14T17:24:34Z")

</div>

for Chuck’s tool you’ll want to run a repair and a reindex.

Download chucks tool to /mnt/cache/appdata/Plex/ with wget or whatever your downloader of choice is:

`cd /mnt/cache/appdata/Plex/ && wget https://github.com/ChuckPa/PlexDBRepair/releases/download/v0.5.1/DBRepair.sh`

Run chown nobody:users DBRepair.sh & chmod +x DBRepair.sh to give ownership to the docker daemon user/group and allow the script to be executed:

`chown nobody:users DBRepair.sh && chmod +x DBRepair.sh`

Open the plex docker terminal from the docker menu in the unraid webui. In the terminal enter `s6-svc -d /var/run/s6-rc/servicedirs/svc-plex` to stop the plex service in the conainter.

Run chuck’s tool: `cd /config && ./DBRepair.sh`

Choose Option 4 (repair), then 3 (I think, whatever the reindex option is).

Exit the script once its done and restart the plex service with `s6-svc -u /var/run/s6-rc/servicedirs/svc-plex`

for the binary modifications just run the sed commands already provided above.

---

<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:** [December 14, 2022, 11:19pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/128 "2022-12-14T23:19:42Z")

</div>

> [@chaberman43](#):
>
> I was reading through all this and went to make the recommended change to 4096 and I see it’s already set.

Why do you say that?

As of **1.30.1.6483** , the `cache_size` binary patch is no longer applicable. The first parameter is no longer hardcoded in PMS; the built-in `Database Cache Size` setting supersedes it. Yay!

```auto
sed -i.orig \
 -e 's/cache_size=2000/cache_size=8192/' \ # No longer in the code
 -e 's/cache_size = 4096/cache_size = 8192/' \
 'Plex Media Server'

```

The second one is still present in the server, but we learned previously that it’s less important anyway.

* * *

The `page_size` of the template database that Plex ships is still **1024**. I would still suggest changing the `page_size` from **1024** to at least the modern SQLite default of **4096**.

```auto
# Show the original page_size
"Plex SQLite" com.plexapp.plugins.library.db "PRAGMA page_size"

# Set the desired page_size,
# disable WAL,
# VACUUM to rewrite the pages
# re-enable WAL (not strictly necessary, Plex will do this)
"Plex SQLite" com.plexapp.plugins.library.db "PRAGMA page_size=4096" "PRAGMA journal_mode=DELETE" "VACUUM" "PRAGMA journal_mode=WAL"
"Plex SQLite" com.plexapp.plugins.library.blobs.db "PRAGMA page_size=4096" "PRAGMA journal_mode=DELETE" "VACUUM" "PRAGMA journal_mode=WAL"

# Show the new page_size
"Plex SQLite" com.plexapp.plugins.library.db "PRAGMA page_size"

```

Larger values like **16384** (or larger) may make sense, but would be influenced by filesystem and operating system. **4096** is certainly safe and will be an improvement.

---

<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:** [December 15, 2022, 12:16am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/129 "2022-12-15T00:16:57Z")

</div>

> [@Volts](#):
>
> The first parameter is no longer hardcoded in PMS; the built-in `Database Cache Size` setting supercedes it. Yay!

The superseding result though is `-2000` ie 2000 kibibytes.

---

<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:** [December 15, 2022, 1:02am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/130 "2022-12-15T01:02:30Z")

</div>

@jasonsansone, I’m missing something - what do you mean? Where do you see that?

Where `cache_size` was previously fixed to **2000** in Plex’s code, it’s now parameterized. I don’t think Plex has ever used SQLite’s **-2000** default.

---

<div class="post-metadata">

**Author:** ![chaberman43](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@chaberman43](https://forums.plex.tv/u/chaberman43)\
**Post date:** [December 15, 2022, 3:33am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/131 "2022-12-15T03:33:44Z")

</div>

I was referring to the page\_size for the existing SQLite DB setting you mentioned in this post: [Suggested SQLite3 DB Optimizations - #2 by Volts](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/2)

I went to check mine before I set it to 4096 as you recommended and I saw it was already set to 4096. As far as I recall I’ve never changed it so I assumed Plex must have changed it…

 ![Screenshot_20221214-213949](https://global.discourse-cdn.com/plex/original/4X/e/f/7/ef74d4a72c967a401484f19dde0a65f490e2ee80.png)

---

<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:** [December 15, 2022, 4:06am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/132 "2022-12-15T04:06:49Z")

</div>

Interesting, thank you. I’ll check again.

I verified that the template .db file Plex ships with is still 1024. I’ll check if Plex seems to be doing any migrations to the file at startup, or perhaps during periodic Optimization.

But perhaps more likely - have you ever manually repaired or rebuilt the database? Or used Chuck’s script or anything else to repair/rebuild/optimize?

An unintended (good) side effect of those processes is that they’ll use a 4096-byte page.

---

<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:** [December 15, 2022, 4:25am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/133 "2022-12-15T04:25:21Z")

</div>

I did a fresh install of PMS on both FreeBSD and Windows. Both were **1024**. I restarted PMS, and I did a database `Optimize`. Still **1024**.

The file `Resources/com.plexapp.plugins.library.db` that ships with Plex has `page_size` of **1024** , and that file is copied whenever Plex creates any databases.

So I don’t think Plex has changed anything.

So @chaberman43, I’m pretty sure you’ve done something to alter your database `page_size` at some point - which is a good thing!

I’m trying to convince Plex to change the default `page_size` of the template file they ship, so other people get the better default too! Hopefully the fact that the Support document and Chuck’s script have been converting people to a better `page_size` will help convince them. 🙂

---

<div class="post-metadata">

**Author:** ![chaberman43](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@chaberman43](https://forums.plex.tv/u/chaberman43)\
**Post date:** [December 15, 2022, 11:34am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/134 "2022-12-15T11:34:20Z")

</div>

Yeah It was Chuck’s script, I tried it out to see what kind of performance improvement it would yield and I didn’t realize it would increase my page\_size in the new DB.

---

<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:** [December 16, 2022, 1:46am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/135 "2022-12-16T01:46:01Z")

</div>

I was wrong and didnt realize this was a new setting.

 ![image](https://global.discourse-cdn.com/plex/original/4X/1/d/1/1d1df3b2112f4b0c0c7834465ac4968c0971f859.png)

---

<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 19, 2022, 10:58am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/136 "2022-12-19T10:58:59Z")

</div>

Thank you very much for your help!

Is the Binary modification after the update still a thing?

---

<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:** [December 19, 2022, 11:35am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/137 "2022-12-19T11:35:42Z")

</div>

Not necessary anymore

---

<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 23, 2022, 11:58am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/138 "2022-12-23T11:58:15Z")

</div>

I would like to express my thanks.  
Plex has become noticeably faster with this improvement.

---

<div class="post-metadata">

**Author:** ![surinas1](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@surinas1](https://forums.plex.tv/u/surinas1)\
**Post date:** [January 1, 2023, 7:51pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/139 "2023-01-01T19:51:37Z")

</div>

![1d1df3b2112f4b0c0c7834465ac4968c0971f859_2_690x126](https://global.discourse-cdn.com/plex/original/4X/a/b/2/ab2ed0dd13634cbe0527e630607e10f1f87d5a0f.png)

With this latest beta update, those of you who have tried it, how much would be the ideal size for the cache?

In a new plex installation I see 40M inside the interface but if I access the database it appears at -2000.  
I have tried making the changes from DB Browser for SQLite and with Plex SQLite and whatever I do it always gives me a value of -2000, also if I change it in the interface of the latest beta and I always put a high value in PRAGMA Cache Size is -2000 is that correct?

---

<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:** [January 1, 2023, 8:07pm UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/140 "2023-01-01T20:07:10Z")

</div>

> In a new plex installation I see 40M inside the interface but if I access the database it appears at -2000.  
> I have tried making the changes from DB Browser for SQLite and with Plex SQLite and whatever I do it always gives me a value of -2000, also if I change it in the interface of the latest beta and I always put a high value in PRAGMA Cache Size is -2000 is that correct?

The cache is established per connection. When you make a query, thats a separate independent connection. The plex binary is establishing its own connection and creating it using the cache defined in that new option. There isn’t any way to verify the cache size independently.

---

<div class="post-metadata">

**Author:** ![surinas1](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@surinas1](https://forums.plex.tv/u/surinas1)\
**Post date:** [January 2, 2023, 12:29am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/141 "2023-01-02T00:29:38Z")

</div>

Ok, thanks for the clarification.  
And according to your experience, how much cache size should be added in the new plex interface?

---

<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:** [January 2, 2023, 2:08am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/142 "2023-01-02T02:08:41Z")

</div>

That depends on the size of your DB and how much memory is available on the server.

---

<div class="post-metadata">

**Author:** ![florinvlaicu](https://avatars.discourse-cdn.com/v4/letter/f/f05b48/32.png) [@florinvlaicu](https://forums.plex.tv/u/florinvlaicu)\
**Post date:** [January 2, 2023, 7:44am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/143 "2023-01-02T07:44:36Z")

</div>

The default (40 MB) is 5 times bigger than what was suggested here (8 MB).  
How would one compute the size of the cache?

---

<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:** [January 2, 2023, 9:24am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/144 "2023-01-02T09:24:01Z")

</div>

I am not an expert, but maybe you should just try some values and see if it brings an improvement. In your browser you can see how fast an Internet page loads under “Examine” → “Network”.

---

<div class="post-metadata">

**Author:** ![surinas1](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@surinas1](https://forums.plex.tv/u/surinas1)\
**Post date:** [January 4, 2023, 9:56am UTC](https://forums.plex.tv/t/suggested-sqlite3-db-optimizations/794749/145 "2023-01-04T09:56:25Z")

</div>

I have already been able to update to the latest beta version, I will start doing a few tests and seeing the results, thanks

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

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