Database Corruption

same problem here https://forums.plex.tv/discussion/comment/1677862#Comment_1677862 . this is obviously something with the latest PMS release. I restored a previous db and it worked for a day and this morning same error (There was an unexpected error loading this library). We need a hotfix on this ASAP.

The plex db should be BULLETPROOF! Rebuilding a db from scratch when you have a lot of content is a PAINFUL experience that takes forever. I’m a huge plex supporter but honestly issues like this could put a blemish on the product.

@maccrory said:
same problem here https://forums.plex.tv/discussion/comment/1677862#Comment_1677862 . this is obviously something with the latest PMS release. I restored a previous db and it worked for a day and this morning same error (There was an unexpected error loading this library). We need a hotfix on this ASAP.

The plex db should be BULLETPROOF! Rebuilding a db from scratch when you have a lot of content is a PAINFUL experience that takes forever. I’m a huge plex supporter but honestly issues like this could put a blemish on the product.

There isn’t a bug that causes corruption that would stop the library loading.

However, there is an issue that stops the normal dB integrity check from working. The following steps are needed.

If the server logs show that there is a dB corruption, save a copy of the database and then run

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'" 

Now run the integrity checks

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

And then attempt repair

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

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

run another check to confirm repair ok

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

And launch PMS with the repaired dB

@sa2000 said:

@maccrory said:
same problem here https://forums.plex.tv/discussion/comment/1677862#Comment_1677862 . this is obviously something with the latest PMS release. I restored a previous db and it worked for a day and this morning same error (There was an unexpected error loading this library). We need a hotfix on this ASAP.

The plex db should be BULLETPROOF! Rebuilding a db from scratch when you have a lot of content is a PAINFUL experience that takes forever. I’m a huge plex supporter but honestly issues like this could put a blemish on the product.

There isn’t a bug that causes corruption that would stop the library loading.

However, there is an issue that stops the normal dB integrity check from working. The following steps are needed.

If the server logs show that there is a dB corruption, save a copy of the database and then run

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'" 

Now run the integrity checks

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

And then attempt repair

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

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

run another check to confirm repair ok

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

And launch PMS with the repaired dB

@SA2000 thanks, the above fix appears to have worked. appreciate the help

I was having the same problem.

It was fixed after only these steps:
systemctl stop plexmediaserver
sqlite3 /dir/com.plexapp.plugins.library.db “DROP index ‘index_title_sort_naturalsort’”
sqlite3 /dir/com.plexapp.plugins.library.db “DELETE from schema_migrations where version=‘20180501000000’”

I’ve actually been having a lot of trouble since the last update. When the update first came out I suddenly had a significant amount of permissions errors I had to resolve. The application stops responding to queries a few times per week, usually in the middle of transcoding.

@GenJack said:
I was having the same problem.

It was fixed after only these steps:
systemctl stop plexmediaserver
sqlite3 /dir/com.plexapp.plugins.library.db “DROP index ‘index_title_sort_naturalsort’”
sqlite3 /dir/com.plexapp.plugins.library.db “DELETE from schema_migrations where version=‘20180501000000’”

I’ve actually been having a lot of trouble since the last update. When the update first came out I suddenly had a significant amount of permissions errors I had to resolve. The application stops responding to queries a few times per week, usually in the middle of transcoding.

Do you have any logs for when the problems were encountered ?

Those changes should only allow you to do a PRAGMA integrity_check. They do not in themselves resolve a corruption or any other issue

I attached the before (file.4.log) and after (file.log). That before log went immediately to the same symptoms it usually takes an hour or so to reach.

I’d like to clarify that I don’t think the title of this post is correct, since the “database is corrupt” from the Original Poster was kind of a question. I was having his same problem as described: “My problem is that PMS every hour becomes unvailable and i have to reboot.”

Looks like that might be the oldest log that wasn’t involved with me troubleshooting (I attempted a fresh install to make sure it wasn’t my OS)

After I was able to read the database with my version of sqlite, I did an integrity check and it reported the database was fine. I then started Plex back up to continue troubleshooting, but it has worked fine since. I’ve watched a few hours of video now with no issues. Maybe it’s still broken and I’m just being lucky though.

@GenJack said:
I attached the before (file.4.log) and after (file.log). That before log went immediately to the same symptoms it usually takes an hour or so to reach.

I’d like to clarify that I don’t think the title of this post is correct, since the “database is corrupt” from the Original Poster was kind of a question. I was having his same problem as described: “My problem is that PMS every hour becomes unvailable and i have to reboot.”

Looks like that might be the oldest log that wasn’t involved with me troubleshooting (I attempted a fresh install to make sure it wasn’t my OS)

After I was able to read the database with my version of sqlite, I did an integrity check and it reported the database was fine. I then started Plex back up to continue troubleshooting, but it has worked fine since. I’ve watched a few hours of video now with no issues. Maybe it’s still broken and I’m just being lucky though.

Could have been a deadlock issue. Cannot tell without debug logging. You have disabled the server debug logging.

If you do get lockouts and need to restart the server, please make sure you run with debug logging enabled. Restart the server after enabling it so that all logs from launch time onwards have logging enabled

When you get a lockout note the time and restart the server and download the logs zip and attach

I had the same problem, corruption of database, directories were not scanned anymore.

sqlite3 com.plexapp.plugins.library.db “PRAGMA integrity_check”
reported two corrupt indexes:
wrong # of entries in index sqlite_autoindex_fts4_metadata_titles_segdir_1
wrong # of entries in index index_metadata_items_on_changed_at

Solution (in my case):

  1. Shutdown PMS
  2. run sqlite3 com.plexapp.plugins.library.db
  3. “reindex xxxxxx” on all corrupt indexes.
  4. Exit sqlite3 and start PMS again.

Indexing worked again. :slight_smile:

Well, I have this same warning about the natualsort collation.

so I tried to drop the index, but the index didn’t exist… Thank goodness I made a copy of the DB, because running the schema migration delete completely HOSED my DB. did a restore, now I am back to the single error…

I assume things have changed a bit with the build since this post?

what commands should I use to remove the reference from the DB?

P.S. Perhaps it might not be known, but if you post something that may be specific to a version of Plex, and future versions it may no longer be valid, it might be prudent to mention that… then again, how would you know?

Any help is much appreciated!

If the index is not present and you try to DROP it then there will be an error returned but that should not matter

The current instructions for repair are here
https://support.plex.tv/articles/201100678-repair-a-corrupt-database/
and for restore from backup
https://support.plex.tv/articles/202485658-restore-a-database-backed-up-via-scheduled-tasks/

Yes I tried those instructions… They did nothing to improve the error… thanks anyway.