Suggested SQLite3 DB Optimizations

Gotcha, use “Plex SQLite” instead :+1:

“Plex Media Server includes its own SQLite command line interpreter.”

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

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.

1 Like

Sample script code here.

You could also run this in cron to regularly reduce the WAL to keep it from getting bloated.

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.

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.

Those are done :slight_smile: 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

That means it did f all right?

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.

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.

It isn’t missing. The second line is related to iTunes only. It is intentionally omitted since it is unnecessary.

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

Thank you!

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!

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

Hopefully someone finds it useful!

1 Like

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.

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.

1 Like

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.

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.

1 Like

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?

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?

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

1 Like

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.

1 Like