"There was an unexpected error loading this library" when accessing all movies- server bug?

OK, after following this post i also got a similar message to maccrory got upon running the last line for the repair process (see below), but the db seems to be working fine. The Xs were substituted below for my name. There is apparently a lot of discussion of the “Error: no such collation sequence: naturalsor” and “Error: near line xxxxxxx: no such collation sequence: naturalsort” at the two following plex forum topics.


First the check showed the following
:Databases XXXXXX$ sqlite3 com.plexapp.plugins.library.db “PRAGMA integrity_check”
Error: no such collation sequence: naturalsort

Then I ran the three lines of code and the last line gave the following:
:Databases XXXXXX$ sqlite3 com.plexapp.plugins.library.db < dump.sql
Error: near line 875398: no such collation sequence: naturalsort

Well - so much for restoring an older db version. listing movies was fine most of the day yesterday. i woke up this morning and BOOM, same error when i tried to list Movies: There was an unexpected error loading this library Please visit our forums if you continue to experience problems. I attached new plex now … how do i proceed now ?

Sorry didnt mean to put this entry in twice - dont see a delete function

so woke up this morning and same error occurred . looks like this is def a problem from the 2 posts above. any ideas of what to do now ? wait for a fix? i def DO NOT want to delete and rebuild my db - that is a LONG and PAINFUL process when you have a lot of content.

@maccrory said:
Well - so much for restoring an older db version.

So it appears that the corruption was already present in the backup as well.

OR maybe: how much space is left on drive C:? If it runs out of free space, the DB can get damaged really quick.
Instruct your anti-virus to leave the plex data folder alone.

If you have enough space free on C, we may need to perform the proper repair procedure after all.
There are 2 lines more now, compared with the instructions in the help article.
Do you still have the backup of the database we made yesterday? Let’s start with this one.

Shut down Plex Server before doing any of the below:

sqlite3 com.plexapp.plugins.library.db "DROP index 'index_title_sort_naturalsort'"
sqlite3 com.plexapp.plugins.library.db "DELETE from schema_migrations where version='20180501000000'"

It is of utmost importance, that the above commands are copied exactly as written, because they alter the database directly.

Now run the integrity checks

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

And then attempt repair
export the DB to SQL file:

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

Now rename the original, corrupted DB file
Linux/Mac: mv com.plexapp.plugins.library.db com.plexapp.plugins.library.db.original
Windows: rename com.plexapp.plugins.library.db com.plexapp.plugins.library.db.original

reimport the SQL dump back into a new DB file:

sqlite3 com.plexapp.plugins.library.db < dump.sql

Run another check to establish if repair was successful

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

at the end of the procedure, move these 3 files out to a safe place (outside of Plex’s data), just in case you want to revert it:

com.plexapp.plugins.library.db-shm
com.plexapp.plugins.library.db-wal
com.plexapp.plugins.library.db.original

Otto,

I just ran the following commands you listed above from another post (see below). after running the 2 commands the db says OK on status check - guessing that means no errors. but i’m confused about the last sentence below - does it mean that when i relaunch plex that it will become corrupt again ?

@sa2000 said:
There is a problem with running the PRAGMA integrity_check and the following steps should allow you to run it and repair any corruptions

sqlite3 com.plexapp.plugins.library.db "DROP index 'index_title_sort_naturalsort'"
sqlite3 com.plexapp.plugins.library.db "DELETE from schema_migrations where version='20180501000000'"

After these changes, you should be able to run the integrity check and go through the process of repair if there is corruption

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

Note: by deleting the schema_migrations entry, the update for naturalsort would get applied again on launch of Plex Media Server and the database schema update would be re-applied

@maccrory said:
I just ran the following but i’m confused about the last line. does it mean that when i relaunch plex that it will become corrupt again ?

@sa2000 said:
Note: by deleting the schema_migrations entry, the update for naturalsort would get applied again on launch of Plex Media Server and the database schema update would be re-applied

No. That is just a technical explanation why the integrity check failed before.
The first 2 lines will remove the incompatible index table and instruct Plex Server to recreate the index upon next start.