I've recently run into a long lasting problem with my Plex Media Server (PMS), where doing any search, be it in the PMS web interface itself, or any of Plex's apps, would always end up with "No matches found." Even if I was looking directly AT matches right on the screen, with my very own eyes (which are still pretty good, I might add, even at my age. ).
In fact, I whipped up a couple short videos of the "bug" happening right here:
Plex Web Interface | Plex Android |
I put "bug" in quotes, because technically this isn't a bug; it's more of a "break". Something broke. Read on for more.
If you want to skip all of the nerdy details, and jump straight to the actual solution, just click HERE.
So to track the issue down, what I did was this:
(NOTE: You don't need to do any of this in order to fix your own. I'm just detailing the steps for those with geeky curiosity).
Important first step. Shut down your Plex server. Go to it's tray icon, right-click it, then click "Exit".
If you haven't already, for any other reason, head to your PMS web interface, and enable Logging. I like to set mine to "verbose", but you don't have to. If you haven't changed the port your PMS server is on, the page is typically here. Be sure to click the "Advanced" button, then the "Debug" tab. (More detail on this procedure can be found on our tutorial here: How To Enable or Disable Logging In Plex Media Server (PMS))
Next, I headed to the folder on my computer where Plex stores all of it's logs. In my case, since I store my Plex's data folder on my 4TB Z: drive, the folder path looks like this: Z:\Data\Plex Media Server\Logs, then I deleted all log files in that folder, so that I could start from scratch, and it'd be a little easier to sift through. Not a requirement, but a bit more helpful.
Tip: There's the "You can view the debug logs here." link below the combo-box where you enable debug logging, that takes you to a useful page of log info, however, in my testing it didn't seem to update properly for me, so I'd recommend using both, that log page, and viewing the actual log files in a text editor, for full info on what's going on in PMS behind the scenes.
Now that the server is off, and all log files deleted, restart the server.
Go to your Plex server's Dashboard, and do a search or 2, for things you KNOW exist in your library. It'll of course, take you to the Search Results page, saying the usual "No matches found."Make a mental note of the search phrase(s) you used.
Open up Plex Media Server.log (pretty sure it was that one. I'm going off memory and there are several log files generated, so if it wasn't that exact one, it's in one of those ) with something like Notepad, or your favorite text editor.
Do a Search with the editor for whichever search term(s) you used, and you'll eventually come across something that looks similar to this:
<br /> Sep 24, 2015 20:42:54:143 [9292] ERROR - SQLITE3:9CA7840C, 11, database corruption at line 67420 of [8a8ffc862e]<br /> Sep 24, 2015 20:42:54:143 [9292] ERROR - SQLITE3:9CA7840C, 11, statement aborts at 12: [select distinct metadata_items.id from metadata_items join media_items on media_items.metadata_item_id=metadata_items.id join media_parts on media_parts.media_item_id=media_items.id<br /> Sep 24, 2015 20:42:54:143 [9292] ERROR - Soci Exception handled: sqlite3_statement_backend::loadRS: database disk image is malformed<br /> Sep 24, 2015 20:42:54:146 [15196] DEBUG - Completed: [::ffff:192.168.0.195:55866] GET /search?local=1&query=hulk (20 live) TLS GZIP 12ms 486 bytes 500<br /> Sep 24, 2015 20:42:54:158 [14704] ERROR - SQLITE3:9CA7840C, 11, database corruption at line 67420 of [8a8ffc862e]<br /> Sep 24, 2015 20:42:54:158 [14704] ERROR - SQLITE3:9CA7840C, 11, statement aborts at 14: [select distinct metadata_items.id from metadata_items join metadata_items as parents on parents.id=metadata_items.parent_id join metadata_items as grandparents on grandparents.id=pa<br /> Sep 24, 2015 20:42:54:158 [14704] ERROR - Soci Exception handled: sqlite3_statement_backend::loadRS: database disk image is malformed<br />
Aha! Well, there's your problem! Your database is corrupted. That's never a good thing. Now, according to the Plex docs this is supposed to be a very rare thing, however, from what I've deduced it's not so rare, and to be honest, I didn't to anything particularly 'hard' on the server, ever. It just happened through very simple, basic usage. This is why I said above that something 'broke', as opposed to it being a 'bug', though, in reality there may very well be a bug hidden somewhere in the code that's causing database corruption.
Anyway, onto the ...
Fortunately, when it comes to databases, corruptions are (usually) not something to panic about, especially if you're really, really lucky. It's usually just a matter of running a database repair on the database, and things will work again. Hopefully without having any data loss at all. Here's how to repair the Plex database:
I normally use a slick database program called Navicat to do a lot of my database work, so I'll show how I did it with Navicat. However, Navicat is a commercial software, so it costs money. Going off memory (again), I think it does have a free trial period though, which may be good enough if you're only wanting to do a 1-time fix. The Plex database is a SQLite database, so as long as you have software that can repair SQLite3, it'll work, and there are several free options out there, easily found with a quick Google search. I'll even point you to one a bit later.
Important first step. Shut down your Plex server.
Next step, (after opening Navicat of course), is to open the Plex database in Navicat. This is done simply by drag & drop of the file com.plexapp.plugins.library.db onto the Navicat window. The file is found in Z:\Data\Plex Media Server\Plug-in Support\Databases (Remember, you probably have it somewhere other than Z:\).
NOTE: Create a backup of this file first, in case of catastrophe! Simply highlight it, hold down the CTRL button, and drop the copy to an open space in the same folder. Rename it to: com.plexapp.plugins.library.db.OLD
Right-click the database in Navicat, and hover over "Maintain". What I did first was "Vacuum Database", then "Reindex Database", as shown in the screenshot below:
Now, go ahead and restart your PMS server.
Once it's running, open the Dashboard in it's web interface; at this point, none of my original rows (such as my libraries) were showing anymore, only my "On Deck" row showed, and those weren't even correct. Don't panic ...
To the left, where there's a Gear icon, first click "Update Libraries", give it a bit to do it's thing, then click "Optimize". Again, give it a bit to finish. This is all just so that PMS will get things all sorted out again, it's own way, and then optimized, since we re-index everything. Re-indexing is somewhat akin to dumping everything out into a box, then re-adding it all back in, in a more organized fashion, loosely speaking. (More details on this process here, if interested: Plex Media Server: How To Update Your Libraries & Optimize Your Database)
Finally, shut PMS down again, and restart it.
Walah! Once it's restarted, if everything when as expected, all of your usual rows and libraries will be there again, with no noticeable differences. you can (and should, before spending time customizing your stuff again) verify by going into a few of the movies that you know you had previously customized the poster, background, tags (etc.) of, to make sure it's the same as before. In my case, everything was perfect.
Go ahead and try some new searches now, they'll show up as they always should have.
For some reason, if things didn't work out so well, you can just shut PMS down, delete com.plexapp.plugins.library.db and rename the one I told you to back up first from com.plexapp.plugins.library.db.OLD to com.plexapp.plugins.library.db, and restart PMS. Of course you'll be back at square 1 where you were unable to get search results, but at least no harm, no foul in what we have just done. Then you can try to hunt down another method of getting things to work properly.
Here are a couple useful links to the official Plex support website, relevant to the topic as well, including a free method of repairing the database if you don't already have either Navicat, or some other SQLite utility.
Restore a Database Backed Up via 'Scheduled Tasks':
This is another method, if you prefer to restore a previously backed up database that worked / wasn't corrupt. I usually prefer to repair mine, because I customize my library so much that I hate the thought of having to redo any of them, if the restored database was a bit too old. But that's just me, you may not mind.
Repair a Corrupt Database:
Here're the instructions from the official Plex website on basically how to do what I just described above; albeit, using a free SQLite download. Possibly a bit more confusing to understand for your beginner to average Plex user than our tutorial.
We're always loving new ways to do the same thing, especially if they make life easier! Post 'em if ya got 'em!
Olympus
Single & Not Looking
Got a reply in the Plex forums regarding this, from a user, that I thought would be helpful to add here, as far as a potential cause of the original corruption:
Read your write-up - Database corruption. You are storing your plex database on Z: drive. If that is a network drive, then that could have been the cause.
It's a good point. I agree that it could cause a corruption, if for example the PMS server was running, and the mapped network drive became disconnected. Here's my reply over there.
Thanks Astrofisher. I could see that causing a potential issue as well. In my case, I've never stored the db on a network drive. I just set the drive letter to Z: because it's a 4 tb external USB drive. It's easier for me too spot at the end of the list of drives in tree views that way.
Though, maybe due to it being a USB drive, maybe that could've caused it at some point as well. Maybe during a system crash or something, and it wasn't "ejected" properly first.
Moral of the story, if you're (or I am) running your PMS data folder on either a mapped network drive, or external USB drive, and corruption keeps happening, it might be best to move it to a permanently mounted, local hard drive.