{"id":263,"date":"2019-04-17T16:26:02","date_gmt":"2019-04-17T16:26:02","guid":{"rendered":"https:\/\/pure-media.info\/?p=263"},"modified":"2019-04-17T16:26:50","modified_gmt":"2019-04-17T16:26:50","slug":"repair-a-corrupt-plex-database","status":"publish","type":"post","link":"https:\/\/pure-media.info\/index.php\/2019\/04\/17\/repair-a-corrupt-plex-database\/","title":{"rendered":"Repair a Corrupt Plex Database"},"content":{"rendered":"\n<p>it is possible for your main Plex Media Server database to become corrupted. For instance, it might happen if the computer is turned off without first quitting Plex Media Server. In such a situation, you can attempt to repair the database.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Tip!: It\u2019s always a good idea make a backup copy of the database file before doing any work on it.<\/pre>\n\n\n\n<p>First we need to stop the Plex Media Server and locate the database<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo service plexmediaserver stop<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Database location (ubuntu)\n\/var\/lib\/plexmediaserver\/Library\/Application Support\/Plex Media Server\/Plug-in Support\/Databases<\/pre>\n\n\n\n<p>Now that plex is stopped we can check the database. This does require you have sqlite3 installed and ready to use. (Place holder to sqlite3 setup). <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Check for Corruption<\/h3>\n\n\n\n<p>\n\nYou can run commands to check how corrupt the database might be. Even if the results come back \u201cOK\u201d, it\u2019s still possible for there to be issues with a database, though.\n\n<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo cp com.plexapp.plugins.library.db com.plexapp.plugins.library.db.original\n\nsudo sqlite3 com.plexapp.plugins.library.db \"DROP index 'index_title_sort_naturalsort'\"\n\nsudo sqlite3 com.plexapp.plugins.library.db \"DELETE from schema_migrations where version='20180501000000'\"\n\nsudo sqlite3 com.plexapp.plugins.library.db \"PRAGMA integrity_check\"<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"mce_8\">Run Database Repair<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">Even if the integrity check doesn\u2019t return errors, it can still sometimes help to try and repair the database. In order to try and \u201crepair\u201d the database, you can perform a dump followed by a restore to get it back to normal. Run the following commands in the Command Prompt in order. <\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo mv com.plexapp.plugins.library.db com.plexapp.plugins.library.db.original\n\nsudo sqlite3 com.plexapp.plugins.library.db \"DROP index 'index_title_sort_naturalsort'\"\n\nsudo sqlite3 com.plexapp.plugins.library.db \"DELETE from schema_migrations where version='20180501000000'\"\n\nsudo sqlite3 com.plexapp.plugins.library.db .dump > dump.sql\n\nsudo rm com.plexapp.plugins.library.db\n\nsudo sqlite3 com.plexapp.plugins.library.db &lt; dump.sql<\/pre>\n\n\n\n<p> Prior to restarting your Plex Media Server, you should also delete (or backup and move elsewhere) the following two files if they exist alongside the original database: <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">com.plexapp.plugins.library.db-shm\ncom.plexapp.plugins.library.db-wal<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"mce_14\">Start Plex and Check<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo service plexmediaserver start<\/pre>\n\n\n\n<p>Now the plex database has been repaired and can be tested. In some cases, the repair process does not fix the problem and a database restore might be required to restore plex. <\/p>\n\n\n\n<p>Stop plex again using the steps above and move to the last resort to restore the backup<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"mce_22\">Last Resort &#8211; Restore Plex Database from backup<\/h4>\n\n\n\n<p> One of the many Scheduled Tasks that a Plex Media Server performs is to make regular backups of the core database, which holds things such as your viewstate information and media matching details. Below are the steps to restore from one of those backups<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo mv com.plexapp.plugins.library.db com.plexapp.plugins.library.db-ARBackup\n\nls (list all database backups)\ncom.plexapp.plugins.library.db-2019-04-19\ncom.plexapp.plugins.library.db-2019-04-22\ncom.plexapp.plugins.library.db-2019-04-25\n\nsudo cp com.plexapp.plugins.library.db-2019-04-25 com.plexapp.plugins.library.db\n\nsudo rm com.plexapp.plugins.library.db-shm\nsudo rm com.plexapp.plugins.library.db-wal<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>it is possible for your main Plex Media Server database to become corrupted. For instance, it might happen if the<\/p>\n","protected":false},"author":1,"featured_media":90,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[85],"tags":[356,355,2,70,7],"class_list":["post-263","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tech-tip","tag-corrupt","tag-database","tag-plex","tag-restore","tag-ubuntu"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/pure-media.info\/wp-content\/uploads\/2016\/04\/plex-updater.png?fit=250%2C250&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7oBs4-4f","jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/pure-media.info\/index.php\/wp-json\/wp\/v2\/posts\/263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pure-media.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pure-media.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pure-media.info\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pure-media.info\/index.php\/wp-json\/wp\/v2\/comments?post=263"}],"version-history":[{"count":0,"href":"https:\/\/pure-media.info\/index.php\/wp-json\/wp\/v2\/posts\/263\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pure-media.info\/index.php\/wp-json\/wp\/v2\/media\/90"}],"wp:attachment":[{"href":"https:\/\/pure-media.info\/index.php\/wp-json\/wp\/v2\/media?parent=263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pure-media.info\/index.php\/wp-json\/wp\/v2\/categories?post=263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pure-media.info\/index.php\/wp-json\/wp\/v2\/tags?post=263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}