Corrupt database

Hello.

I've run into an issue with a corrupt database, and unfortunately I've been unable to fix it. I found the following thread: https://support.plex.tv/hc/en-us/articles/201100678-Repair-a-Corrupt-Database, which does address this issue, however was unable to get any of the windows commands to do anything. In fact, there are three various downloads for windows, but I was only able to get the shell one to run. However, I'm not able to run any of the commands from the OS X section. That is, even though I do change the filepath to the Windows filepath, none of the commands do anything. They just put me on a new row, which is exactly the same as what happens when typing any random incorrect command. Anyone know how to use this program on Windows?

 

1 Like

Hello.

I've run into an issue with a corrupt database, and unfortunately I've been unable to fix it. I found the following thread: https://support.plex.tv/hc/en-us/articles/201100678-Repair-a-Corrupt-Database, which does address this issue, however was unable to get any of the windows commands to do anything. In fact, there are three various downloads for windows, but I was only able to get the shell one to run. However, I'm not able to run any of the commands from the OS X section. That is, even though I do change the filepath to the Windows filepath, none of the commands do anything. They just put me on a new row, which is exactly the same as what happens when typing any random incorrect command. Anyone know how to use this program on Windows?

if you are running windows, you need to follow the windows instruction and only the windows instructions - the OSX will never work.

Make sure you are running the windows commands from the location you have installed the SQL download into.

Did you even look at the windows commands? There literally aren't any, it just shows the location of the file and says "run commands similar to the ones above", but my issue is that the commands aren't running.
 
From your response though, I did try to use the actual command prompt (used the sqlite shell previously), but then got the error "unable to open database file", even when running as admin.
Did you even look at the windows commands? There literally aren't any, it just shows the location of the file and says "run commands similar to the ones above", but my issue is that the commands aren't running.
 
From your response though, I did try to use the actual command prompt (used the sqlite shell previously), but then got the error "unable to open database file", even when running as admin.

This may come off as remedial, please don't take it that way as it is not my intention, but are you pointing the commands to:

C:\Users\[WINDOWS USERNAME]\AppData\Local\Plex Media Server\Plug-in Support\Databases\

I'm pointing it to %LOCALAPPDATA%\Plex Media server\..., but it's the same thing. I did a quick test with "cd %LOCALAPPDATA" and it swapped me to ...\AppData\Local\, so it works. 

Ok, just making sure. How big is the library? Would it be a huge undertaking to delete the .db file and rebuild rather than attempt to repair?

I did that, started to rebuild it, then gave up when I realised just how much effort it would take :( Library is huge...

The easiest way is to place the sqlite3.exe file into the folder with your database, then open up a command prompt and cd to that folder.  I have never needed to perform these commands, but the Windows equivalent are as below:

Check file for errors:

sqlite3 com.plexapp.plugins.library.db "PRAGMA integrity_check"

Backup database:

sqlite3 com.plexapp.plugins.library.db ".dump" > dump.sql

Restore database:

sqlite3 com.plexapp.plugins.library.db ".read dump.sql"

Check for errors again to make sure all the errors are gone.  It sounds to me like there is a step missing to clear out the old data.  Personally, after making the backup, I would rename the database, turn on Plex to let it generate a brand new database file, exit Plex, then run the restore command.

It worked o.o Thanks a ton! :D Saved me a few days of trouble that did. 

I ran these commands but it came back with a weird return:
the first command (integrity check) said “ok”
the second finished with no message
the third repeated Error: near line xxxx: unique constraint failed: (name of file).id for about 20000 lines.

Should I just delete it all and start over with a fresh install?

There should be no message after step 2. However it should have created a file called dump.sql.

When doing the 3rd step, rename the old file first to something else.

Please there is any easiest way to solve corrompt database?

Sure. Zip your database file. Upload it to a sharing site. Send me the link. I’ll fix the file and and send it back.

@MovieFan.Plex said:
Sure. Zip your database file. Upload it to a sharing site. Send me the link. I’ll fix the file and and send it back.

Any chance I could get you to try to repair mine ? Been building a very large database and never backed up. Restarted my computer and it cannot connect to the database.

Sure. Send me the link.

Hello @“MovieFan.Plex” ,

I am sorry to disturb but I`m facing a really nasty corruption of my database which I cannot resolve by myself even though I have followed the steps above. To be honest as I am writing this post, I am watching the command prompt scrolling down full of errors after the third step.
So the Check file for errors gave this as a result :

! Plex Media Server\Plug-in Support\Databases>sqlite3 com.plexapp.plugins.library.db “PRAGMA integrity_check”
! *** in database main ***
! Main freelist: freelist leaf count too big on page 219299
! Main freelist: 2239 of 2241 pages missing from overflow list starting at 219299
! Page 173095: btreeInitPage() returns error code 11
! On tree page 83065 cell 95: Child page depth differs
! On tree page 83065 cell 94: Child page depth differs
! On tree page 126460 cell 7: Rowid 331587 out of order
! On tree page 223739 cell 2: 2nd reference to page 59781
! On tree page 216908 cell 91: Rowid 47430 out of order
! On tree page 216908 cell 90: Rowid 47391 out of order
! On tree page 216908 cell 89: Rowid 47350 out of order
! On tree page 216908 cell 84: Rowid 47144 out of order
! On tree page 216908 cell 75: Rowid 46871 out of order
! On tree page 216908 cell 72: Rowid 46775 out of order
! On tree page 216908 cell 71: Rowid 46742 out of order
! On tree page 216908 cell 70: Rowid 46712 out of order
! On tree page 216908 cell 69: Rowid 46682 out of order
! On tree page 216908 cell 68: Rowid 46656 out of order
! On tree page 216908 cell 66: Rowid 46605 out of order
! On tree page 216908 cell 65: Rowid 46579 out of order
! On tree page 216908 cell 60: Rowid 46461 out of order
! On tree page 216908 cell 59: Rowid 46435 out of order
! On tree page 216908 cell 58: Rowid 46412 out of order
! On tree page 216908 cell 57: Rowid 46381 out of order
! On tree page 216908 cell 30: Rowid 45658 out of order
! On tree page 216908 cell 23: Rowid 45482 out of order
! On tree page 216841 cell 79: Rowid 44696 out of order
! On tree page 216841 cell 57: Rowid 44121 out of order
! On tree page 216157 cell 61: Rowid 29495 out of order
! On tree page 221472 cell 29: Rowid 27391 out of order
! On tree page 221477 cell 31: Rowid 31526 out of order
! On tree page 221470 cell 31: Rowid 31591 out of order
! On tree page 221439 cell 29: Rowid 34906 out of order
! On tree page 221445 cell 30: Rowid 35626 out of order
! On tree page 221499 cell 35: Rowid 36042 out of order
! On tree page 221473 cell 33: Rowid 36438 out of order
! On tree page 221505 cell 26: Rowid 40499 out of order
! On tree page 221462 cell 30: Rowid 41158 out of order
! On tree page 221489 cell 26: Rowid 41337 out of order
! On tree page 221476 cell 26: Rowid 42199 out of order
! On tree page 221459 cell 24: Rowid 42489 out of order
! On tree page 221527 cell 25: Rowid 43138 out of order
! On tree page 221468 cell 27: Rowid 43624 out of order
! On tree page 221471 cell 26: Rowid 44060 out of order
! On tree page 221441 cell 40: Rowid 47166 out of order
! On tree page 221458 cell 23: Rowid 46006 out of order
! On tree page 221509 cell 31: Rowid 46852 out of order
! On tree page 221474 cell 33: Rowid 47031 out of order
! On tree page 221440 cell 26: Rowid 47058 out of order
! On tree page 221466 cell 32: Rowid 47091 out of order
! On tree page 221475 cell 38: Rowid 47411 out of order
! On tree page 168305 cell 62: Rowid 988469 out of order
! On tree page 222910 cell 0: invalid page number 218103808
! On tree page 232972 cell 70: Rowid 988158 out of order
! On tree page 232972 cell 69: Rowid 988156 out of order
! On tree page 232972 cell 68: Rowid 988155 out of order
! Page 221520: btreeInitPage() returns error code 11
! On tree page 232211 cell 9: Rowid 987627 out of order
! On tree page 232211 cell 9: 2nd reference to page 221154
! On tree page 65 cell 12: Rowid 987616 out of order
! On tree page 232208 cell 97: Rowid 987615 out of order
! Page 219197: btreeInitPage() returns error code 11
! On tree page 232208 cell 91: Rowid 987607 out of order
! On tree page 232208 cell 87: Rowid 987603 out of order
! On tree page 232208 cell 79: Rowid 987595 out of order
! On tree page 232208 cell 78: Rowid 987594 out of order
! On tree page 232208 cell 78: 2nd reference to page 221550
! On tree page 232208 cell 76: Rowid 987592 out of order
! On tree page 232208 cell 75: Rowid 987590 out of order
! On tree page 232208 cell 74: Rowid 987589 out of order
! On tree page 232208 cell 73: Rowid 987588 out of order
! On tree page 232208 cell 71: Rowid 987586 out of order
! On tree page 232208 cell 70: Rowid 987585 out of order
! On tree page 232208 cell 69: Rowid 987584 out of order
! On tree page 232208 cell 68: Rowid 987583 out of order
! On tree page 230454 cell 58: Rowid 987464 out of order
! On tree page 223285 cell 1: invalid page number 218103808
! On tree page 230454 cell 32: Rowid 987430 out of order
! Page 219678: btreeInitPage() returns error code 11
! On tree page 230714 cell 96: Rowid 987160 out of order
! Page 221383: btreeInitPage() returns error code 11
! On tree page 230714 cell 70: Rowid 987126 out of order
! On tree page 231567 cell 1: invalid page number 218103808
! Page 219095: btreeInitPage() returns error code 11
! Page 219090: btreeInitPage() returns error code 11
! On tree page 218959 cell 7: Rowid 986330 out of order
! On tree page 218959 cell 4: Rowid 986326 out of order
! On tree page 218959 cell 3: Rowid 986325 out of order
! On tree page 167953 cell 57: Rowid 986316 out of order
! On tree page 167953 cell 50: Rowid 986308 out of order
! On tree page 221540 cell 0: Rowid 977338 out of order
! On tree page 221568 cell 0: Rowid 977339 out of order
! On tree page 221575 cell 0: Rowid 977342 out of order
! On tree page 221561 cell 32: Rowid 977363 out of order
! On tree page 219004 cell 42: 2nd reference to page 231085
! Page 219628: btreeInitPage() returns error code 11
! Page 219130: btreeInitPage() returns error code 11
! Page 219228: btreeInitPage() returns error code 11
! On tree page 219164 cell 1: Rowid 977413 out of order
! On tree page 218869 cell 86: 2nd reference to page 229549
! On tree page 219182 cell 0: Rowid 977415 out of order

The same command after the above procedure (and huge amount of errors during read dump.sql) gave me this

! \Plex Media Server\Plug-in Support\Databases>sqlite3 com.plexapp.plugins.library.db “PRAGMA integrity_check”
! Error: malformed database schema (spellfix_tag_titles) - table spellfix_tag_titles already exists

I`m thinking this could have happened cause of a defective HDD on which I am keeping my Plex folder but now I am stuck with this problem which makes my Plex Server to constantly crash. Besides that my library is kind of veeeeery big so I am not willing to remove and re-scan it.

PS: The most recent functional Database file which I have found (and checked with sqlite3) is from August 2016

Honestly, any help would be appreciated.

Please PM me the zipped database.

The string in the Plex documentation is actually wrong.
The string in the documentation is missing quotes.

Do it like so.
sqlite3 “%LOCALAPPDATA%\Plex Media Server\Plug-in Support\Databases\com.plexapp.plugins.library.db” .dump > dump.sql

Ensure the program sqlite3.exe is in your command path or execute it from the directory it resides.

Note: the quotes are required since the path to the database contains spaces. This confuses the argument parser since a space would indicate another part of the command line argument. The quotes cause the argument to be passed with spaces thus the correct path can be used by sqlite3.exe

Actually, the example in the article shows the command for a Mac, which has the spaces properly escaped. There isn’t an example for Windows, but you are correct. You need quotes whenever there is a space.

That is not the users issue. The command is running, just running into some issues with the actual data. I have seen a few cases where the data got corrupted before a PMS update, then the update was unable to migrate the database to reflect a new schema. The db needs to be manually fixed in these rare cases.

Actually that is wrong.
The documentation shows the command line argument for windows without quotes.
In fact it shows the database path line for windows and tells you to use that argument using the sqlite3 command as above in the ios example.

I understand that was not the issue.
Just wanted to let folks know the correct way to implement the documented database commands.

BTW.
For working with the database exports, Without needing to spend money on Navicat or something else, I found PHPLiteAdmin.php
It’s free and you can import the PMS database to work or play with it. Might help find the corruption.
Dunno
Note. To run phpliteadmin.php you will need to install a LAMP/WAMP stack. I use XAMPP.