# There was an unexpected error loading this library

**URL:** <https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582>\
**Category:** Plex Media Server\
**Tags:** server-linux\
**Created:** [February 22, 2021, 2:31pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582 "2021-02-22T14:31:06Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![MattPC1234](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@MattPC1234](https://forums.plex.tv/u/MattPC1234)\
**Post date:** [February 22, 2021, 2:31pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/1 "2021-02-22T14:31:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![OttoKerner](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ottokerner/32/10079_2.png) [@OttoKerner](https://forums.plex.tv/u/OttoKerner)\
**Post date:** [February 22, 2021, 2:34pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/2 "2021-02-22T14:34:06Z")

</div>

Maybe [Collections giving error, database repair did not work - #2 by OttoKerner](https://forums.plex.tv/t/collections-giving-error-database-repair-did-not-work/691940/2)

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.

---

<div class="post-metadata">

**Author:** ![MattPC1234](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@MattPC1234](https://forums.plex.tv/u/MattPC1234)\
**Post date:** [February 22, 2021, 2:41pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/3 "2021-02-22T14:41:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![OttoKerner](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ottokerner/32/10079_2.png) [@OttoKerner](https://forums.plex.tv/u/OttoKerner)\
**Post date:** [February 22, 2021, 2:42pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/4 "2021-02-22T14:42:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![OttoKerner](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ottokerner/32/10079_2.png) [@OttoKerner](https://forums.plex.tv/u/OttoKerner)\
**Post date:** [February 22, 2021, 2:45pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/6 "2021-02-22T14:45:48Z")

</div>

Please define “thousands”.

How much RAM?  
Virtualized?  
Any non-default setup choices regarding the [Plex data folder](https://support.plex.tv/hc/en-us/articles/202915258-Where-is-the-Plex-Media-Server-data-directory-located- "Plex data folder"), like NFS shares, or SD cards, or MergerFS, or other shenanigans?

---

<div class="post-metadata">

**Author:** ![MattPC1234](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@MattPC1234](https://forums.plex.tv/u/MattPC1234)\
**Post date:** [February 22, 2021, 2:52pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/8 "2021-02-22T14:52:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![OttoKerner](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ottokerner/32/10079_2.png) [@OttoKerner](https://forums.plex.tv/u/OttoKerner)\
**Post date:** [February 22, 2021, 2:55pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/9 "2021-02-22T14:55:31Z")

</div>

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.

> [@MattPC1234](#):
>
> I do have NFS shares

I am only interested if your _[Plex data folder](https://support.plex.tv/articles/202915258-where-is-the-plex-media-server-data-directory-located/)_ has been put on a NFS share.  
The media files are a different matter.

> [@MattPC1234](#):
>
> but these have been working for years without issue.

Maybe they have been working while your library was smaller?

> [@MattPC1234](#):
>
> 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,

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

---

<div class="post-metadata">

**Author:** ![OttoKerner](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ottokerner/32/10079_2.png) [@OttoKerner](https://forums.plex.tv/u/OttoKerner)\
**Post date:** [February 22, 2021, 3:07pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/11 "2021-02-22T15:07:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![OttoKerner](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ottokerner/32/10079_2.png) [@OttoKerner](https://forums.plex.tv/u/OttoKerner)\
**Post date:** [February 22, 2021, 3:18pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/13 "2021-02-22T15:18:42Z")

</div>

Your database is corrupt:

```auto
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.

---

<div class="post-metadata">

**Author:** ![MattPC1234](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@MattPC1234](https://forums.plex.tv/u/MattPC1234)\
**Post date:** [February 22, 2021, 3:34pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/14 "2021-02-22T15:34:40Z")

</div>

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?

```auto
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**

---

<div class="post-metadata">

**Author:** ![MattPC1234](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@MattPC1234](https://forums.plex.tv/u/MattPC1234)\
**Post date:** [February 22, 2021, 3:35pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/15 "2021-02-22T15:35:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![OttoKerner](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ottokerner/32/10079_2.png) [@OttoKerner](https://forums.plex.tv/u/OttoKerner)\
**Post date:** [February 22, 2021, 3:38pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/16 "2021-02-22T15:38:40Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![MattPC1234](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@MattPC1234](https://forums.plex.tv/u/MattPC1234)\
**Post date:** [February 22, 2021, 3:41pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/18 "2021-02-22T15:41:08Z")

</div>

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

> **[Where is the Plex Media Server data directory located? | Plex Support](https://support.plex.tv/articles/202915258-where-is-the-plex-media-server-data-directory-located/)**
>
> The main Plex Media Server data directory location will vary based on your operating system. Below are the default locations....

---

<div class="post-metadata">

**Author:** ![MattPC1234](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@MattPC1234](https://forums.plex.tv/u/MattPC1234)\
**Post date:** [February 22, 2021, 3:54pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/19 "2021-02-22T15:54:54Z")

</div>

Here are my steps, clarified.

CD into “/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/” as per [here](https://support.plex.tv/articles/202915258-where-is-the-plex-media-server-data-directory-located/).

Run a repair as per [here](https://support.plex.tv/articles/201100678-repair-a-corrupt-database/).

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.

---

<div class="post-metadata">

**Author:** ![OttoKerner](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ottokerner/32/10079_2.png) [@OttoKerner](https://forums.plex.tv/u/OttoKerner)\
**Post date:** [February 22, 2021, 4:13pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/20 "2021-02-22T16:13:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MattPC1234](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@MattPC1234](https://forums.plex.tv/u/MattPC1234)\
**Post date:** [February 22, 2021, 4:27pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/21 "2021-02-22T16:27:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MattPC1234](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@MattPC1234](https://forums.plex.tv/u/MattPC1234)\
**Post date:** [February 22, 2021, 6:25pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/22 "2021-02-22T18:25:19Z")

</div>

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? 🙂

---

<div class="post-metadata">

**Author:** ![ChuckPa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/chuckpa/32/79710_2.png) [@ChuckPa](https://forums.plex.tv/u/ChuckPa)\
**Post date:** [February 22, 2021, 7:59pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/23 "2021-02-22T19:59:03Z")

</div>

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 🙂

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

---

<div class="post-metadata">

**Author:** ![ChuckPa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/chuckpa/32/79710_2.png) [@ChuckPa](https://forums.plex.tv/u/ChuckPa)\
**Post date:** [February 22, 2021, 8:52pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/25 "2021-02-22T20:52:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MattPC1234](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@MattPC1234](https://forums.plex.tv/u/MattPC1234)\
**Post date:** [March 14, 2021, 3:28pm UTC](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582/28 "2021-03-14T15:28:01Z")

</div>

Make sure to add this step:

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

[Next page](https://forums.plex.tv/t/there-was-an-unexpected-error-loading-this-library/693582.md?page=2)
