Suggested SQLite3 DB Optimizations

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.

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.

2 Likes

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!

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.

# 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.

The superseding result though is -2000 ie 2000 kibibytes.

@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.

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

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…

1 Like

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.

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. :slight_smile:

1 Like

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.

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

2 Likes

Thank you very much for your help!

Is the Binary modification after the update still a thing?

Not necessary anymore

1 Like

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

1 Like

1d1df3b2112f4b0c0c7834465ac4968c0971f859_2_690x126

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?

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.

1 Like

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

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

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

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”.

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