This post started as a desperate plea for help and then ended up with me accidentally finding a solution for a really corrupted Plex database. Read on if you’re at the point of desperation where the standard Plex “Repair a corrupt database” didn’t work for you.
Server Version#: 1.21.1.3795
Player Version#: 4.48.1 (Web)
Hey all!
Yesterday, I started getting “There was an unexpected error loading this library” for the “Recommended” tab in Plex Web, and “This library is currently empty” on Plex Mobile for Android. If I switch to the “Library” tab on either, I can see my music and play it fine, but “Recommended” seems to be FUBAR’ed.
So in searching the forums, it seems my database might be corrupted… so I run a sqlite integrity check and this was the output:
Page 1179857: btreeInitPage() returns error code 11
Page 1179855: btreeInitPage() returns error code 11
Page 1179850: btreeInitPage() returns error code 11
Page 1179849: btreeInitPage() returns error code 11
Page 1179846: btreeInitPage() returns error code 11
Page 1179853: btreeInitPage() returns error code 11
On tree page 1179779 cell 5: Child page depth differs
On tree page 1179779 cell 4: Child page depth differs
On tree page 275180 cell 10: 2nd reference to page 275147
On tree page 275180 cell 10: Child page depth differs
On tree page 275180 cell 9: Child page depth differs
Page 275316 is never used
Page 275317 is never used
Page 275318 is never used
Page 275319 is never used
Page 275320 is never used
Page 275321 is never used
Page 275322 is never used
Page 275323 is never used
Page 275324 is never used
Page 275325 is never used
Page 275326 is never used
Page 275327 is never used
Page 275328 is never used
Page 275329 is never used
Page 275330 is never used
Page 275331 is never used
Page 275332 is never used
Page 275333 is never used
Page 275334 is never used
Page 275335 is never used
Page 275336 is never used
Page 275337 is never used
Page 275338 is never used
Page 275339 is never used
Page 275340 is never used
Page 275341 is never used
Page 275342 is never used
Page 275343 is never used
Page 275344 is never used
Page 275345 is never used
Page 275346 is never used
Page 275347 is never used
Page 275348 is never used
Page 275349 is never used
Page 275350 is never used
Page 275351 is never used
Page 275352 is never used
Page 275353 is never used
Page 275354 is never used
Page 275355 is never used
Page 275356 is never used
Page 275357 is never used
Page 1179851 is never used
Page 1179852 is never used
Error: database disk image is malformed
Oof. So I go though the steps here… but the problem is that the last step where you write the dump.sql back into com.plexapp.plugins.library.db results in a lot of churning, and ultimately, a zero-byte com.plexapp.plugins.library.db from a large dump.sql.
So then I figured I’d just check out my backups, but the only thing I have are the blobs, despite checking in my settings that it’s checked for “back up database every three days.” The blobs are notably smaller than the com.plexapp.plugins.library.db file, so I’m assuming I’m boned there.
So then I thought I might get clever and attempt a sqlite “.recover” seen here - which produced a file smaller than the original, but bigger than the auto-backup blobs. Unfortunately, Plex just fails to start with that recovery as the com.plexapp.plugins.library.db.
I’m feeling pretty screwed here. I have a ton of playlists and my database is over 1GB. Would really rather not have to manually rebuild all of this if I don’t have to. Any suggestions?
EDIT:
In doing a tail -f of the logs, I realized the not-so-clever “.recover” option I mentioned earlier was actually moderately-clever. My Plex database is actually 1.5GB and because it’s so large, after the “.recover” action, it spent quite some time on the following steps:
Dec 15, 2020 15:54:54.336 [0x7fbb569d8780] DEBUG - Analyzing database.
Dec 15, 2020 15:54:57.745 [0x7fbb569d8780] DEBUG - Vacuuming database.
Once I just let it sit in this state and finally proceed, it worked swimmingly. It has to do this before it will start the GUI or respond on the web port, so make sure you’re SSH’ed in and watching the logs live. My “Recommendations” tab is now fixed and it’s running pretty snappy, and I recommend that this “.recover” option be added to the official doc on recovering the database.
I’m adding my Plex server log here for posterity.
(File removed)
So to clarify for everyone, since this technique has now helped a couple others in the last 24 hours, here’s what you do:
In the “Repair a Corrupt Database” article, take “Run a Repair” all the way through Step 3. Instead of doing Step 4 there, try this - I’m assuming you’re using a POSIX-compliant shell here and not Windows:
4.) sqlite3 com.plexapp.plugins.library.db ".recover" | sqlite3 out.db
5.) mv out.db com.plexapp.plugins.library.db
Then run back through the “Check for Corruption” steps and see if it throws any errors. If not, you might be better off than you were before! Start up Plex with this new DB and tail the Plex Media Server.log to see if you get the “Analyzing/Vacuuming database” entries.