Plex DB | PlexGuide.com

Plex DB

  • Stop using Chrome! Download the Brave Browser via >>> [Brave.com]
    It's a forked version of Chrome with native ad-blockers and Google's spyware stripped out! Download for Mac, Windows, Android, and Linux!
Welcome to the PlexGuide.com
Serving the Community since 2016!
Register Now

Admin9705

Administrator
Project Manager
Donor
Jan 17, 2018
5,156
2,114
Last edited:

daveftw84

Governer
Original poster
Donor
Jan 18, 2018
270
33
i showed you how to fix this in a pm

---- Automatically Merged Double Post ----

https://forums.plex.tv/t/plex-library-performance-tip/176195

---- Automatically Merged Double Post ----

The following is a rough set of steps I went through to change the PRAGMA default_cache_size in my environment. I'm using containers, but the steps are easily translated to any environment.
1) stopped the plex service (docker exec -it container /bin/bash then in the container s6-svc -d /var/run/s6/services/plex)
2) Double check to make sure all related plex services are stopped (ps auxwwwwf)
3) kill any remaining plex services (kill $PID)
4) Install sqlite tools (apt update && apt install sqlite)
5) modify the pragma setting:
- (sqlite3 /config/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db)
- (PRAGMA default_cache_size = 20000;)
- (ctrl-d)
6) start plex back up (s6-svc -u /var/run/s6/services/plex)
Now, unfortunately I read that default_cache_size is a depreciated option. The proper way to fix this would be to set cache_size on the initiator connection (within the actual plex code). The default value is 2000 (feel free to google this if your interested in knowing what this translates to ram usage wise). I opted for 10x and most of my problems went away. I have about 6TB of library, and will probably go to 20x or 30x as I progressively add the entire 6TB.
If your logs look like:
==> /config/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log <==
Jan 17, 2017 00:25:45.384 [0x7f93d6ffd700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:27:17.590 [0x7f93c4ffe700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:27:18.604 [0x7f93c4ffe700] ERROR - Failed to begin transaction (../Statistics/StatisticsManager.h:191) (tries=1): Cannot begin transaction. database is locked
Jan 17, 2017 00:27:50.697 [0x7f93c4ffe700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:28:22.069 [0x7f93c4ffe700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:28:23.084 [0x7f93c4ffe700] ERROR - Failed to begin transaction (../Statistics/StatisticsManager.h:191) (tries=1): Cannot begin transaction. database is locked
Jan 17, 2017 00:28:24.441 [0x7f93c4ffe700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:28:25.454 [0x7f93c4ffe700] ERROR - Failed to begin transaction (../Statistics/StatisticsManager.h:191) (tries=2): Cannot begin transaction. database is locked
Jan 17, 2017 00:29:28.383 [0x7f93d6ffd700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:29:29.397 [0x7f93d6ffd700] ERROR - Failed to begin transaction (../Statistics/StatisticsManager.h:191) (tries=1): Cannot begin transaction. database is locked
Jan 17, 2017 00:29:31.067 [0x7f93d6ffd700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:29:32.081 [0x7f93d6ffd700] ERROR - Failed to begin transaction (../Statistics/StatisticsManager.h:191) (tries=2): Cannot begin transaction. database is locked
Jan 17, 2017 00:31:34.466 [0x7f93baff1700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:31:35.480 [0x7f93baff1700] ERROR - Failed to begin transaction (../Statistics/StatisticsManager.h:191) (tries=1): Cannot begin transaction. database is locked
Jan 17, 2017 00:31:37.235 [0x7f93baff1700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:31:38.250 [0x7f93baff1700] ERROR - Failed to begin transaction (../Statistics/StatisticsManager.h:191) (tries=2): Cannot begin transaction. database is locked
Jan 17, 2017 00:31:39.774 [0x7f93baff1700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:31:40.789 [0x7f93baff1700] ERROR - Failed to begin transaction (../Statistics/StatisticsManager.h:191) (tries=3): Cannot begin transaction. database is locked
Jan 17, 2017 00:32:13.765 [0x7f93c4ffe700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:34:47.468 [0x7f93baff1700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:34:48.483 [0x7f93baff1700] ERROR - Failed to begin transaction (../Statistics/StatisticsManager.h:191) (tries=1): Cannot begin transaction. database is locked
Jan 17, 2017 00:34:50.241 [0x7f93baff1700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:35:21.287 [0x7f93d27fd700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:35:22.302 [0x7f93d27fd700] ERROR - Failed to begin transaction (../Statistics/StatisticsManager.h:191) (tries=1): Cannot begin transaction. database is locked
Jan 17, 2017 00:35:23.879 [0x7f93d27fd700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:35:55.076 [0x7f93d27fd700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:36:26.132 [0x7f93d27fd700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:36:58.152 [0x7f93d27fd700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:37:30.121 [0x7f93baff1700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:37:31.136 [0x7f93baff1700] ERROR - Failed to begin transaction (../Statistics/StatisticsManager.h:191) (tries=1): Cannot begin transaction. database is locked
Jan 17, 2017 00:37:32.547 [0x7f93baff1700] WARN - Waited one whole second for a busy database.
This can most likely help you.
 
Last edited:

Admin9705

Administrator
Project Manager
Donor
Jan 17, 2018
5,156
2,114
Oh I was confused about it. Apologize, was busy converting all those containers. I have 6 things to follow back on
 

daveftw84

Governer
Original poster
Donor
Jan 18, 2018
270
33
no your cool, i know you are doing alot just quite wheels dont get the oil.
 

Admin9705

Administrator
Project Manager
Donor
Jan 17, 2018
5,156
2,114
no your cool, i know you are doing alot just quite wheels dont get the oil.
Ya. I wish I knew more about the error but know as much as you do :D
 

timekills

VIP
Staff
Donor
Sep 12, 2018
367
192
i showed you how to fix this in a pm

---- Automatically Merged Double Post ----

https://forums.plex.tv/t/plex-library-performance-tip/176195

---- Automatically Merged Double Post ----

The following is a rough set of steps I went through to change the PRAGMA default_cache_size in my environment. I'm using containers, but the steps are easily translated to any environment.
1) stopped the plex service (docker exec -it container /bin/bash then in the container s6-svc -d /var/run/s6/services/plex)
2) Double check to make sure all related plex services are stopped (ps auxwwwwf)
3) kill any remaining plex services (kill $PID)
4) Install sqlite tools (apt update && apt install sqlite)
5) modify the pragma setting:
- (sqlite3 /config/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db)
- (PRAGMA default_cache_size = 20000;)
- (ctrl-d)
6) start plex back up (s6-svc -u /var/run/s6/services/plex)
Now, unfortunately I read that default_cache_size is a depreciated option. The proper way to fix this would be to set cache_size on the initiator connection (within the actual plex code). The default value is 2000 (feel free to google this if your interested in knowing what this translates to ram usage wise). I opted for 10x and most of my problems went away. I have about 6TB of library, and will probably go to 20x or 30x as I progressively add the entire 6TB.
If your logs look like:
==> /config/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log <==
Jan 17, 2017 00:25:45.384 [0x7f93d6ffd700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:27:17.590 [0x7f93c4ffe700] WARN - Waited one whole second for a busy database.
Jan 17, 2017 00:27:18.604 [0x7f93c4ffe700] ERROR - Failed to begin transaction (../Statistics/StatisticsManager.h:191) (tries=1): Cannot begin transaction. database is locked
Jan 17, 2017 00:37:32.547 [0x7f93baff1700] WARN - Waited one whole second for a busy database.
This can most likely help you.
First, the directory for the database in #5 is wrong. If you're going to execute this from inside the Plex container (which I recommend another way I'll explain further down) then step #5 should be:

sqlite3 /config/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db

HOWEVER...
Since that file is set in the Docker creation to be stored externally in the /opt/appdata/Plex folder (more specifically /opt/appdata/plex/database/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db), you can make the changes MUCH more simply, from the server instead of inside the container trying to stop services.

  1. Stop the Plex Docker container (either of two ways listed below: )
    1. From host/server command line docker stop plex or...
    2. From Portainer, select the Plex instance and stop it.
  2. From host/server command line, install sqlite tools
    1. apt update && apt install sqlite
  3. Modify the pragma setting:
    1. sqlite3 "/opt/appdata/plex/database/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db"
  4. Change the PRAGMA amount from default 2000 to recommended 20000 or whatever:
    1. PRAGMA default_cache_size = 20000;
  5. Exit SQLite
    1. .quit
  6. Restart plex
    1. From host/server command line docker start plex or...
    2. From Portainer, select the Plex instance and start it.
 
Last edited:

daveftw84

Governer
Original poster
Donor
Jan 18, 2018
270
33
here is what i did,
stop in port
cd "/opt/appdata/plex/database/Library/Application Support/Plex Media Server/Plug-in Support/Databases"
sqlite3 com.plexapp.plugins.library.db
PRAGMA default_cache_size = 300000;
crtl +d
start plex in port

but i read this doesnt work anymore

---- Automatically Merged Double Post ----

"now, unfortunately I read that default_cache_size is a depreciated option. The proper way to fix this would be to set cache_size on the initiator connection (within the actual plex code). The default value is 2000 (feel free to google this if your interested in knowing what this translates to ram usage wise). I opted for 10x and most of my problems went away. I have about 6TB of library, and will probably go to 20x or 30x as I progressively add the entire 6TB."

---- Automatically Merged Double Post ----

https://hastebin.com/cilitawafu.bash
 
Last edited:

timekills

VIP
Staff
Donor
Sep 12, 2018
367
192
Deprecated doesn't mean doesn't work.

https://github.com/timekills/plex-db-speedup/blob/master/README.md

I modified the script in the hastebin posting to work with Plexguide installs. The README file above explains how to use it, but basically just cd /opt/appdata/plex/scripts (or any directory you want to save the file to) then:

Bash:
git clone https://github.com/timekills/plex-db-speedup.git
cd plex-db-speedup
chmod a+x plexdbfix.sh
./plexdbfix.sh
 
Last edited:
  • Like
Reactions: 1 user

daveftw84

Governer
Original poster
Donor
Jan 18, 2018
270
33
very nice, thank you!!
I found some other stuff too that would be nice to implant into plexguide
a ram disk for just the plex database and a script to make a back up of the database from ram disk every so often
https://hastebin.com/voqopewece.fstab
https://hastebin.com/awamuzoyoy.bash

---- Automatically Merged Double Post ----

Deprecated doesn't mean doesn't work.

https://github.com/timekills/plex-db-speedup/blob/master/README.md

I modified the script in the hastebin posting to work with Plexguide installs. The README file above explains how to use it, but basically just cd /opt/appdata/plex/scripts (or any directory you want to save the file to) then:

Bash:
git clone https://github.com/timekills/plex-db-speedup.git
cd plex-db-speedup
chmod a+x plexdbfix.sh
./plexdbfix.sh

after running the script, plex wont start up. in port logs its flooded with starting plex server.


---- Automatically Merged Double Post ----

should I be worried about that?
permission issues?

---- Automatically Merged Double Post ----

chown -R 1000:1000 "/opt/appdata/plex/database/Library/Application Support/Plex Media Server/Plug-in Support/Databases/"
 
Last edited:

daveftw84

Governer
Original poster
Donor
Jan 18, 2018
270
33
update.
i set the server to trim the drives with a cronjob at 330 am.
then at 4am the server runs the script you see above.
by before 4:10 am the server is back up and running plex's built in maintenance

all my issues are gone now
 

Admin9705

Administrator
Project Manager
Donor
Jan 17, 2018
5,156
2,114
Exciting stuff!
 

timekills

VIP
Staff
Donor
Sep 12, 2018
367
192
very nice, thank you!!
I found some other stuff too that would be nice to implant into plexguide
a ram disk for just the plex database and a script to make a back up of the database from ram disk every so often
https://hastebin.com/voqopewece.fstab
https://hastebin.com/awamuzoyoy.bash

---- Automatically Merged Double Post ----




after running the script, plex wont start up. in port logs its flooded with starting plex server.


---- Automatically Merged Double Post ----

should I be worried about that?
permission issues?

---- Automatically Merged Double Post ----

chown -R 1000:1000 "/opt/appdata/plex/database/Library/Application Support/Plex Media Server/Plug-in Support/Databases/"
Yeah, the file permissions is tough, as it is somewhat based on any changes the user made. But you're right - for the default PG user it should be 1000:1000.

I'll update the script.
 

Admin9705

Administrator
Project Manager
Donor
Jan 17, 2018
5,156
2,114
Yeah, the file permissions is tough, as it is somewhat based on any changes the user made. But you're right - for the default PG user it should be 1000:1000.

I'll update the script.
is this ready where we can do a gitpull to add?
 

timekills

VIP
Staff
Donor
Sep 12, 2018
367
192
I've tried it on a new install (PG Edge version) as well as a couple live servers.
Works quickly; the docker stop, DB backup, fix, and restart takes ~45 seconds and Plex was back operational within about two minutes.

I did add the sqlite check and install to the script; the requirement for sqlite makes where this is installed in PG a bit more of a decision. Do we want sqlite to be installed on the host (as I've done with the script), or include it in the Plex container so it's more portable and there by default?

No. I'm doing some checks on a few servers first.
I want to run it on a few fresh installs to make sure it isn't just working for me.
Close...I'll let you know.
 
Last edited:

Admin9705

Administrator
Project Manager
Donor
Jan 17, 2018
5,156
2,114
I've tried it on a new install (PG Edge version) as well as a couple live servers.
Works quickly; the docker stop, DB backup, fix, and restart takes ~45 seconds and Plex was back operational within about two minutes.

I did add the sqlite check and install to the script; the requirement for sqlite makes where this is installed in PG a bit more of a decision. Do we want sqlite to be installed on the host (as I've done with the script), or include it in the Plex container so it's more portable and there by default?

No. I'm doing some checks on a few servers first.
I want to run it on a few fresh installs to make sure it isn't just working for me.
Close...I'll let you know.
sure just let me know what works for you :D
 

timekills

VIP
Staff
Donor
Sep 12, 2018
367
192
I'd say if you put it in the Tools section, it makes sense as is. That already includes some host-based apps like the VPN and network/system auditor. Plus, that way it's only used if the user knows what and why they'd want to execute the script.

I'm not certain where it occurs, but it seems as though sqlite is installed already even on the new install I tested. However, that may have happened during the install of some required stuff for xwin and VNC remote.
Regardless, it checks and installs if not already installed.
 

3days

Experienced
Jan 24, 2018
55
6
I'd say if you put it in the Tools section, it makes sense as is. That already includes some host-based apps like the VPN and network/system auditor. Plus, that way it's only used if the user knows what and why they'd want to execute the script.

I'm not certain where it occurs, but it seems as though sqlite is installed already even on the new install I tested. However, that may have happened during the install of some required stuff for xwin and VNC remote.
Regardless, it checks and installs if not already installed.
hrm, when running the script I just get:

Starting Plex Media Server. x1000

in a loop, the docker never actually starts.

Any idea why?
 

pYTTH

Elite
Staff
Nov 1, 2018
242
102
can you paste error logs?
 

Recommend NewsGroups

      Up To a 58% Discount!

Trending