There was an unexpected error loading this library

Server Version#: 1.21.4.4054-bab510e86
Player Version#: All players

This is not a new issue. There are hundreds of message board posts, dating back to 2016, describing the same problem. I have tried all of the troubleshooting steps. I optimized my database. I refreshed the metadata. I spent an hour walking through the horribly described troubleshooting steps for repairing a database. I even removed the entire server and re-added it (countless hours of work, gone). None of it works. I still see the ‘Unexpected Error’ whenever opening my TV shows library.

I have been running Plex on Ubuntu for years and have never encountered this problem.

It’s also extremely disappointing that a company we pay a subscription to can not even be bothered to offer any technical support outside of this forum.

Maybe Collections giving error, database repair did not work - #2 by OttoKerner

A second option would be to delete the client’s preferences.
i.e. log out of the client and uninstall it from your device (if it’s an Android or iOS or Smart TV device.)
In the case of the web app, delete all cookies of the domain plex.tv, and clear the browser cache.

Thanks - however I don’t have any collections setup. I don’t believe there’s a collections setting to disable it anyway, but correct me if I’m wrong.

I don’t think the client is the problem. I have been able to replicate this issue on five different machines, including the server machine.

To clarify - I can occasionally see the ‘Recommended’ stub in my Movies library. If I click the ‘Library’ tab, I get the error. For TV shows both Recommended and Library tabs throw the error.

What kind of machine is this running on and how many episodes do you have in your library?

Please define “thousands”.

How much RAM?
Virtualized?
Any non-default setup choices regarding the Plex data folder, like NFS shares, or SD cards, or MergerFS, or other shenanigans?

Possibly related - Ubuntu has crashed a number of times during the process of re-adding my content to the new server. The error logs indicated some problems with Plex files, but Ubuntu’s fsck corrected them, and I was able to boot again.

AMD 64 includes a wide range of CPU’s as well. From very weak to high-end. A more precise definition of the cpu type could provide valuable data points.

I am only interested if your Plex data folder has been put on a NFS share.
The media files are a different matter.

Maybe they have been working while your library was smaller?

That could indicate indeed problems.
However, “some problems with Plex files” is not exactly enlightening. The actual error messages would be needed here.

Server logs are available in the web app, under
Settings - Server - Manage - Troubleshoot

However, they will only contain useful information, if the server has been set to activate “debug logs”, under Server - Settings - ‘Show Advanced’ - General
(Do not enable ‘verbose’ logs!)
This configuration change must be done before a restart of the server.

Your database is corrupt:

Feb 22, 2021 10:12:47.892 [0x7fed3f7fe700] ERROR - SQLITE3:(nil), 11, database corruption at line 79051 of [bf8c1b2b7a]
Feb 22, 2021 10:12:47.892 [0x7fed3f7fe700] ERROR - SQLITE3:(nil), 11, statement aborts at 14: [select grandparents.id from metadata_items INDEXED BY index_metadata_items_on_library_section_id_and_metadata_type_and_added_at join metadata_items as parents on metadata_items.parent_
Feb 22, 2021 10:12:47.892 [0x7fed3f7fe700] ERROR - Soci Exception handled: sqlite3_statement_backend::loadRS: database disk image is malformed

This was very likely caused during those “problems with Plex files”.
You have no choice than to perform the repair process again.
If you leave it in this state, the DB may deteriorate beyond salvation.

Make sure that the free space on the volume which houses the plex data folder never goes near zero. Because if that happens, database corruption is almost inevitable.

Okay! At least we got the cause identified now! A step in the right direction. I have tried the database repair multiple times with no luck. Can you see where I am going wrong?

matt@matt-desktop:~$ sudo service plexmediaserver start
[sudo] password for matt: 
matt@matt-desktop:~$ cd $PLEX_HOME/Library/Application\ Support/Plex\ Media\ Server/Plug-in\ Support/Databases/
bash: cd: /Library/Application Support/Plex Media Server/Plug-in Support/Databases/: No such file or directory
matt@matt-desktop:~$ sudo service plexmediaserver stop
matt@matt-desktop:~$ cd $PLEX_HOME/Library/Application\ Support/Plex\ Media\ Server/Plug-in\ Support/Databases/
bash: cd: /Library/Application Support/Plex Media Server/Plug-in Support/Databases/: No such file or directory
matt@matt-desktop:~$ cp com.plexapp.plugins.library.db com.plexapp.plugins.library.db.original
cp: cannot stat 'com.plexapp.plugins.library.db': No such file or directory
matt@matt-desktop:~$ cd /usr/lib/plexmediaserver/resources
bash: cd: /usr/lib/plexmediaserver/resources: No such file or directory
matt@matt-desktop:~$ cd /usr/lib/plexmediaserver
matt@matt-desktop:/usr/lib/plexmediaserver$ cp com.plexapp.plugins.library.db com.plexapp.plugins.library.db.original
cp: cannot stat 'com.plexapp.plugins.library.db': No such file or directory
matt@matt-desktop:/usr/lib/plexmediaserver$ sqlite3 com.plexapp.plugins.library.db "DROP index 'index_title_sort_naturalsort'"
Error: unable to open database "com.plexapp.plugins.library.db": unable to open database file
matt@matt-desktop:/usr/lib/plexmediaserver$ sudo su
root@matt-desktop:/usr/lib/plexmediaserver# cp com.plexapp.plugins.library.db com.plexapp.plugins.library.db.original
cp: cannot stat 'com.plexapp.plugins.library.db': No such file or directory
root@matt-desktop:/usr/lib/plexmediaserver# sqlite3 com.plexapp.plugins.library.db "DROP index 'index_title_sort_naturalsort'"
Error: no such index: index_title_sort_naturalsort
root@matt-desktop:/usr/lib/plexmediaserver# cd /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/
bash: cd: too many arguments
root@matt-desktop:/usr/lib/plexmediaserver# cp com.plexapp.plugins.library.db com.plexapp.plugins.library.db.original
root@matt-desktop:/usr/lib/plexmediaserver# sqlite3 com.plexapp.plugins.library.db "DROP index 'index_title_sort_naturalsort'"
Error: no such index: index_title_sort_naturalsort
root@matt-desktop:/usr/lib/plexmediaserver# sqlite3 com.plexapp.plugins.library.db "DELETE from schema_migrations where version='20180501000000'"
Error: no such table: schema_migrations
root@matt-desktop:/usr/lib/plexmediaserver# sqlite3 com.plexapp.plugins.library.db "PRAGMA integrity_check"
ok
root@matt-desktop:/usr/lib/plexmediaserver# cp com.plexapp.plugins.library.db com.plexapp.plugins.library.db.original
root@matt-desktop:/usr/lib/plexmediaserver# sqlite3 com.plexapp.plugins.library.db "DROP index 'index_title_sort_naturalsort'"
Error: no such index: index_title_sort_naturalsort
root@matt-desktop:/usr/lib/plexmediaserver# sqlite3 com.plexapp.plugins.library.db "DELETE from schema_migrations where version='20180501000000'"
Error: no such table: schema_migrations
root@matt-desktop:/usr/lib/plexmediaserver# sqlite3 com.plexapp.plugins.library.db .dump > dump.sql
root@matt-desktop:/usr/lib/plexmediaserver# rm com.plexapp.plugins.library.db
root@matt-desktop:/usr/lib/plexmediaserver# sqlite3 com.plexapp.plugins.library.db < dump.sql
root@matt-desktop:/usr/lib/plexmediaserver# chown plex:plex com.plexapp.plugins.library.db

MODERATOR EDIT: Legibility

I should add - my database is located on an SSD that is 4.1% occupied, so I don’t think space could be the cause.

I am no Linux guy, so my knowledge is limited. But the above error messages indicate that you are in the totally wrong folder.

Maybe @ChuckPa can assist?

Entirely possible. I believe this is the correct folder for my Plex Db based off this article:

Here are my steps, clarified.

CD into “/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/” as per here.

Run a repair as per here.

Step 1 - no error
Step 2 - Error: no such index: index_title_sort_naturalsort
Step 3 - Error: no such table: schema_migrations
Step 4 - no error
Step 5 - no error
Step 6 - no error
Step 7 - Neither of these files ( com.plexapp.plugins.library.db-shm or com.plexapp.plugins.library.db-wal`) are listed as per the output of ‘ls’.

‘ls’ shows:
Cache Media
Codecs Metadata
com.plexapp.plugins.library.db plexmediaserver.pid
com.plexapp.plugins.library.db.original Plug-ins
‘Crash Reports’ ‘Plug-in Support’
dump.sql Preferences.xml
Logs

After starting the server again, I still see the same error.

According to the above error messages, you are not actually touching the database file. You are just blindly committing the lines from the article to your command line.

Please wait for the arrival of @ChuckPa

1 Like

Understood. Thanks again for the help @OttoKerner . Will wait for updates.

I have partially fixed the issue. In my case, the database file was located here:

/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases

I ran the repair after CDing into this file. Now my library displays, and only the ‘recommended’ section is broken. So now
 how do I get rid of recommended? :slight_smile:

I see a lot of confusion here.

Before even diving into any remedy,

What is the FUNCTIONAL issue?

Please elaborate more than just the thread title as it’s about as nondescript as a loaf of bread :slight_smile:

Also, please provide an “Items indexed” count and the ls -la of the Databases directory so I may see what we’re dealing with?

Matt,

Please make a tar.gz of the entire Logs directory under /var/lib/plexmediaserver/Library/Application Support/Plex Media Server and attach it here for me to look at.

Make sure to add this step:

chmod 777 -R /var/lib/plexmediaserver/Library