Plex Media Server keeps crashing

Server Version#: latest docker image
Player Version#: n/a

I’ve been trying to keep a plex media server running for a bit now. I keep getting into weird database states. I have a few movies of various qualities. After adding the movies folder to my library list, it scans a few and then dumps a crash report. Any future scans don’t work since my database is “now corrupted.”

I have some 480p, 1080p, and bluray movies.

As far as I can tell, the logs don’t really show much. Just states that my database is corrupted.

Honestly, I’ve been having this issue for a month now. I keep stopping the server, removing the plugins db file, and praying that adding the library again will just “work”.

Can someone help me debug this issue? Should I be avoiding certain filetypes in my library? Should I be adding one movie at a time instead of a list of folders? I feel so lost with this issue

Have you tried repairing the database?
https://support.plex.tv/articles/repair-a-corrupted-database/

If this keeps happening to your setup… have you had a chance to look into what might be causing the corruption (e.g. hard server shutdowns or loss of server data directory drive while the server is writing to the database)?

I haven’t used the sqlite command line to repair the database – only nuking the whole database file. I would be happy to try to use the command line but I am not sure it will tell me what went wrong.

As far as I can tell, there is no “loss of connection” to the database. The plex media server is running in a docker container and the docker interface (and logs) don’t indicate any kind of spin down. The linked volume is on the same computer. The computer has a brand new hard disk with plenty of space (170/250 GB free).

The media itself is on a networked volume (CIFS) – but as far as I can tell that does not matter especially in regards to the database (which, I want to reiterate, is on the same computer as the running docker image).

Perhaps more information. I seem to have added a br-disk quality movie into the library. I’m not sure if plex supports it. I’ll remove it and setup my server again.

Can you show us the DEBUG PMS server logs ZIP file?

Question: Is the docker /config running on a drive where PMS runs or is that over the LAN/network ?

Here are the relevant PMS logs. I think I did a database refresh (or two) at the start of log file 2. The bluray remux files might be the corrupted files – I have since nuked them and will wipe the database in a bit.

The docker volume for /config is on the same drive as PMS.

Plex Media Server.2.log (1.3 MB)
Plex Media Server.1.log (894.8 KB)
Plex Media Server.log (450.1 KB)

Thank you for the logs.

I see the table corruption.

X_PLEX_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "/usr/lib/plexmediaserver/Plex Media Scanner" --match --type 1 --log-file-suffix " Matcher" --files "/data/media/movies/Sicario (1994)/Sicario (1994) WEBRip-1080p.mp4"
Nov 25, 2023 00:32:28.269 [140560145980216] DEBUG - Activity: updated activity e099204d-0ff2-4cbe-930b-0ef953de8377 - completed 66.0% - Scanning Movies
Nov 25, 2023 00:32:28.269 [140560145980216] DEBUG - Scanner: Processing directory /data/media/movies/Sicario (2015) (parent: yes)
Nov 25, 2023 00:32:28.269 [140560145980216] ERROR - SQLITE3:0x80000001, 11, database corruption at line 84326 of [a29f994989]
Nov 25, 2023 00:32:28.269 [140560145980216] ERROR - SQLITE3:0x80000001, 11, statement aborts at 10: [select directories.id as 'directories_id', directories.library_section_id as 'directories_library_section_id', directories.parent_directory_id as 'directories_parent_directory_id', directories.path as 'directories_path', directories.created_at as 'directories_created_at', directories.updated_at as 'directories_updated_at', directories.deleted_at as 'directories_deleted_at' from directories where library_section_id=? and path=? and parent_directory_id=? order by path] database disk image is malformed
Nov 25, 2023 00:32:28.269 [140560030071608] DEBUG - [JobRunner] Jobs: Starting child process with pid 664
Nov 25, 2023 00:32:28.270 [140560145980216] WARN - Caught exception while scanning Movies: sqlite3_statement_backend::loadOne: database disk image is malformed
Nov 25, 2023 00:32:28.270 [140560145980216] DEBUG - Activity: updated activity e099204d-0ff2-4cbe-930b-0ef953de8377 - completed 100.0% - Scanning Movies
Nov 25, 2023 00:32:28.377 [140560034290488] DEBUG - Native Scanner: Executed Add to Database stage in 0.14 sec.
Nov 25, 2023 00:32:28.383 [140560145980216] DEBUG - Refreshing section 1 of type: 1
Nov 25, 2023 00:32:28.385 [140560019524408] DEBUG - Refreshing 0 IDs.

You have two choices here,

  1. Swap this database (com.plexapp.plugins.library.db) with its backup – but you may not have that (?)

  2. Run my PlexDBRepair utility – INSIDE the container on the command line – and have it help you
    – Attempt to fix the DB (and check it again after fixing)
    – Use a backup of the DB (it will automate and then check everything)

I am concerned about the image being malformed.
This usually only happens when either:

  1. The server computer is shutdown abruptly
  2. PMS is hard-terminated with kill -9 / kill -11 (kill -15 is an orderly shutdown)
  3. The /config (PMS metadata directories) are on a network storage location.

Might any of these apply / have happened?

Here’s my tool which you use inside the container at the command line.
You only need place the DBRepair.sh script inside the /config directory and then make sure it’s executable chmod +x DBRepair.sh

I have examples here in the README.md

It’s text-menu based.

You’ll want to

  1. docker exec -it Container_name bash
  2. cd /config
  3. ./DBRepair.sh
    – Stop PMS,
    – Run Auto repair,
    – Start PMS,
    – Stay at the command line in the container while you check if PMS is working again.
    – exit when you’re happy it’s repaired.

If I do restart my containers, it’s just docker compose down. or its restart variant. I’d assume it’s correctly implemented in the image.

And the /config is local. Welcome to inspect the compose file at GitHub - juanca/servarr: i'm a pirate, arrrr

  1. Starting the container is standard docker – docker start container_name
    Restarting is just as easy docker restart container_name

  2. The trick for you is to get inside the container, stop PMS, but keep the container alive (which my tool will do… or you can stop it with /plex_service.sh -d )

If /config is local to the host then you must have had some abrupt kill action to mess up the DB. It takes PMS a few seconds after the SIGTERM to exit. SIGKILL or other abrupt termination will corrupt it every time.

Okay, I reproduced without the BR-DISKs.

Here are my literal steps:

  • docker compose down plex
  • rm ... all com.plexapp.plugins.library.db files (even backups just to start fresh)
  • rm ... all PMS crash reports
  • docker compose up -d plex
  • docker compose logs -f plex
  • Add Movies library (interestingly, there are 5 movies but initial scan only finds 3, spinners on a couple movie posters)
  • Rescan movies library (all 5 movies now show up, spinners only stop after clicking into movie)
  • (I should have waited but…)
  • Add TV library

BOOM! Crash! No abrupt killing, nothing.

Either there are missing steps on how to “reset” a database. Or there is some “Bobby little tables” exploit.

Logs:

juanca@PLAYAPRO servarr % docker compose logs -f plex
servarr-plex-1  | [migrations] started
servarr-plex-1  | [migrations] no migrations found
servarr-plex-1  | ───────────────────────────────────────
servarr-plex-1  | 
servarr-plex-1  |       ██╗     ███████╗██╗ ██████╗ 
servarr-plex-1  |       ██║     ██╔════╝██║██╔═══██╗
servarr-plex-1  |       ██║     ███████╗██║██║   ██║
servarr-plex-1  |       ██║     ╚════██║██║██║   ██║
servarr-plex-1  |       ███████╗███████║██║╚██████╔╝
servarr-plex-1  |       ╚══════╝╚══════╝╚═╝ ╚═════╝ 
servarr-plex-1  | 
servarr-plex-1  |    Brought to you by linuxserver.io
servarr-plex-1  | ───────────────────────────────────────
servarr-plex-1  | 
servarr-plex-1  | To support LSIO projects visit:
servarr-plex-1  | https://www.linuxserver.io/donate/
servarr-plex-1  | 
servarr-plex-1  | ───────────────────────────────────────
servarr-plex-1  | GID/UID
servarr-plex-1  | ───────────────────────────────────────
servarr-plex-1  | 
servarr-plex-1  | User UID:    1000
servarr-plex-1  | User GID:    1000
servarr-plex-1  | ───────────────────────────────────────
servarr-plex-1  | 
servarr-plex-1  | **** Server already claimed ****
servarr-plex-1  | Docker is used for versioning skip update check
servarr-plex-1  | [custom-init] No custom files found, skipping...
servarr-plex-1  | Starting Plex Media Server. . . (you can ignore the libusb_init error)
servarr-plex-1  | no crontab for abc
servarr-plex-1  | no crontab for root
servarr-plex-1  | [ls.io-init] done.
servarr-plex-1  | Critical: libusb_init failed
servarr-plex-1  | ****** PLEX MEDIA SERVER CRASHED, CRASH REPORT WRITTEN: /config/Library/Application Support/Plex Media Server/Crash Reports/1.32.7.7621-871adbd44/PLEX MEDIA SERVER/2756fa5e-af32-4c25-a08118bb-a689ad97.dmp
servarr-plex-1  | Starting Plex Media Server. . . (you can ignore the libusb_init error)
servarr-plex-1  | Critical: libusb_init failed

Crash report, grepped for errors:

juanca@PLAYAPRO ~ % cat Documents/servarr/plex/Library/Application\ Support/Plex\ Media\ Server/Crash\ Reports/1.32.7.7621-871adbd44/PLEX\ MEDIA\ SERVER/2756fa5e-af32-4c25-a08118bb-a689ad97.dmp.log | grep ERROR -
Nov 25, 2023 21:02:07.658 [140244349512504] ERROR - Unknown metadata type: 
Nov 25, 2023 21:02:08.210 [140244349512504] ERROR - Unknown metadata type: 
Nov 25, 2023 21:02:08.569 [140244349512504] ERROR - Unknown metadata type: 
Nov 25, 2023 21:02:09.356 [140244349512504] ERROR - Unknown metadata type: 
Nov 25, 2023 21:02:09.926 [140244384070456] ERROR - SQLITE3:0x80000001, 26, statement aborts at 1: [BEGIN IMMEDIATE] file is not a database
Nov 25, 2023 21:02:09.930 [140244384070456] ERROR - Failed to begin transaction (/data/jenkins/server/3535737052/Library/Dir.cpp:40) (tries=1): Cannot begin transaction. file is not a database
Nov 25, 2023 21:02:09.955 [140244313652024] ERROR - XML: Entity: line 1:
Nov 25, 2023 21:02:09.955 [140244313652024] ERROR - XML: parser
Nov 25, 2023 21:02:09.955 [140244313652024] ERROR - XML: error :
Nov 25, 2023 21:02:09.955 [140244313652024] ERROR - XML: Start tag expected, '<' not found
Nov 25, 2023 21:02:09.956 [140244313652024] ERROR - XML: Database exception: sqlite3_statement_backend::prepare: file is not a database f
Nov 25, 2023 21:02:09.956 [140244313652024] ERROR - XML: ^
Nov 25, 2023 21:02:09.956 [140244313652024] ERROR - Error parsing content.
Nov 25, 2023 21:02:09.958 [140244313652024] ERROR - Error parsing XML: Error parsing file.
Nov 25, 2023 21:02:09.968 [140244349512504] ERROR - SQLITE3:0x80000001, 26, statement aborts at 20: [select media_items.id from media_items join media_parts on media_parts.media_item_id=media_items.id where file=? and media_items.section_location_id=? and display_offset=?] file is not a database
Nov 25, 2023 21:02:09.969 [140244313652024] ERROR - SQLITE3:0x80000001, 26, statement aborts at 20: [select media_items.id from media_items join media_parts on media_parts.media_item_id=media_items.id where file=? and media_items.section_location_id=? and display_offset=?] file is not a database
Nov 25, 2023 21:02:09.969 [140244349512504] ERROR - Exception assimilating media item in Sicario (1994): sqlite3_statement_backend::loadOne: file is not a database
Nov 25, 2023 21:02:09.972 [140244313652024] ERROR - Native Scanner: Exception executing stage Cloud Match: sqlite3_statement_backend::loadOne: file is not a database
Nov 25, 2023 21:02:09.972 [140244311542584] ERROR - SQLITE3:0x80000001, 26, statement aborts at 479: [select media_items.id as 'media_items_id', media_items.library_section_id as 'media_items_library_section_id', media_items.section_location_id as 'media_items_section_location_id', media_items.metadata_item_id as 'media_items_metadata_item_id', media_items.type_id as 'media_items_type_id', media_items.width as 'media_items_width', media_items.height as 'media_items_height', media_items.size as 'media_items_size', media_items.duration as 'media_items_duration', media_items.bitrate as 'media_items_bitrate', media_items.container as 'media_items_container', media_items.video_codec as 'media_items_video_codec', media_items.audio_codec as 'media_items_audio_codec', media_items.display_aspect_ratio as 'media_items_display_aspect_ratio', 
Nov 25, 2023 21:02:09.979 [140244311542584] ERROR - Thread: Uncaught exception running async task which was spawned by thread 140244343184184: sqlite3_statement_backend::loadRS: file is not a database
Nov 25, 2023 21:02:10.211 [140244384070456] ERROR - SQLITE3:0x80000001, 26, statement aborts at 18: [update section_locations set library_section_id=:section_locations_library_section_id,root_path=:section_locations_root_path,available=:section_locations_available,scanned_at=:section_locations_scanned_at,created_at=:section_locations_created_at,updated_at=:section_locations_updated_at where id=:section_locations_id] file is not a database
Nov 25, 2023 21:02:10.211 [140244384070456] ERROR - SQLITE3:0x80000001, 26, statement aborts at 33: [update library_sections set scanned_at=? where id=?] file is not a database
Nov 25, 2023 21:02:10.213 [140244384070456] ERROR - SQLITE3:0x80000001, 26, statement aborts at 91: [UPDATE 'activities' SET id=:activities_id, parent_id=:activities_parent_id, type=:activities_type, title=:activities_title, subtitle=:activities_subtitle, scheduled_at=:activities_scheduled_at, started_at=:activities_started_at, finished_at=:activities_finished_at, cancelled=:activities_cancelled WHERE id=:activities_id] file is not a database
Nov 25, 2023 21:02:10.213 [140244384070456] ERROR - Saving activity history aborted with soci exception: sqlite3_statement_backend::loadOne: file is not a database
Nov 25, 2023 21:02:10.213 [140244384070456] ERROR - SQLITE3:0x80000001, 26, statement aborts at 91: [UPDATE 'activities' SET id=:activities_id, parent_id=:activities_parent_id, type=:activities_type, title=:activities_title, subtitle=:activities_subtitle, scheduled_at=:activities_scheduled_at, started_at=:activities_started_at, finished_at=:activities_finished_at, cancelled=:activities_cancelled WHERE id=:activities_id] file is not a database
Nov 25, 2023 21:02:10.213 [140244384070456] ERROR - Saving activity history aborted with soci exception: sqlite3_statement_backend::loadOne: file is not a database
Nov 25, 2023 21:02:10.213 [140244384070456] ERROR - LibraryUpdater: exception updating libraries; pausing updates briefly before retrying: sqlite3_statement_backend::loadOne: file is not a database
Nov 25, 2023 21:02:10.440 [140244315761464] ERROR - SQLITE3:0x80000001, 11, database corruption at line 72267 of [a29f994989]
Nov 25, 2023 21:02:10.440 [140244315761464] ERROR - SQLITE3:0x80000001, 11, statement aborts at 16: [delete from taggings where id in (select taggings.id from taggings  join tags on tags.id=taggings.tag_id  where tag_type=? and taggings.metadata_item_id=?)] database disk image is malformed
Nov 25, 2023 21:02:10.451 [140244315761464] ERROR - Thread: Uncaught exception running async task which was spawned by thread 140244345293624: sqlite3_statement_backend::loadOne: database disk image is malformed
Nov 25, 2023 21:02:10.507 [140244343184184] ERROR - Unknown metadata type: 
Nov 25, 2023 21:02:10.652 [140244343184184] ERROR - SQLITE3:0x80000001, 11, database corruption at line 84326 of [a29f994989]
Nov 25, 2023 21:02:10.652 [140244343184184] ERROR - SQLITE3:0x80000001, 11, statement aborts at 10: [DELETE FROM 'main'.'fts4_metadata_titles_icu_segdir' WHERE level = ?] database disk image is malformed
Nov 25, 2023 21:02:10.652 [140244343184184] ERROR - SQLITE3:0x80000001, 11, statement aborts at 178: [update metadata_items set updated_at=null,guid=?,hash=? where id=?] database disk image is malformed
Nov 25, 2023 21:02:10.652 [140244343184184] ERROR - Exception inside transaction (inside=1) (/data/jenkins/server/3535737052/Library/MetadataItem.cpp:3944): sqlite3_statement_backend::loadOne: database disk image is malformed
Nov 25, 2023 21:02:10.652 [140244343184184] ERROR - Exception assimilating media item in The Marvels (2023): sqlite3_statement_backend::loadOne: database disk image is malformed
Nov 25, 2023 21:02:10.744 [140244311542584] ERROR - SQLITE3:0x80000001, 11, database corruption at line 84326 of [a29f994989]
Nov 25, 2023 21:02:10.744 [140244311542584] ERROR - SQLITE3:0x80000001, 11, statement aborts at 10: [DELETE FROM 'main'.'fts4_metadata_titles_icu_segdir' WHERE level = ?] database disk image is malformed
Nov 25, 2023 21:02:10.744 [140244311542584] ERROR - SQLITE3:0x80000001, 11, statement aborts at 277: [update metadata_items set library_section_id=:metadata_items_library_section_id,parent_id=:metadata_items_parent_id,metadata_type=:metadata_items_metadata_type,guid=:metadata_items_guid,hash=:metadata_items_hash,media_item_count=:metadata_items_media_item_count,title=:metadata_items_title,title_sort=:metadata_items_title_sort,original_title=:metadata_items_original_title,studio=:metadata_items_studio,rating=:metadata_items_rating,audience_rating=:metadata_items_audience_rating,rating_count=:metadata_items_rating_count,tagline=:metadata_items_tagline,edition_title=:metadata_items_edition_title,summary=:metadata_items_summary,content_rating=:metadata_items_content_rating,content_rating_age=:metadata_items_content_rating_age,'index'=:
Nov 25, 2023 21:02:10.745 [140244311542584] ERROR - Exception inside transaction (inside=1) (/data/jenkins/server/3535737052/Library/MetadataItem.cpp:1099): sqlite3_statement_backend::loadOne: database disk image is malformed
Nov 25, 2023 21:02:10.746 [140244311542584] ERROR - Exception inside transaction (inside=1) (/data/jenkins/server/3535737052/Library/MetadataItem.cpp:9868): sqlite3_statement_backend::loadOne: database disk image is malformed
Nov 25, 2023 21:02:10.752 [140244311542584] ERROR - Thread: Uncaught exception running async task which was spawned by thread 140244345293624: sqlite3_statement_backend::loadOne: database disk image is malformed
Nov 25, 2023 21:02:13.131 [140244315761464] ERROR - Scanner: error reading match results
Nov 25, 2023 21:02:53.481 [140244366883640] ERROR - [Req#1aa] Unknown metadata type: folder
Nov 25, 2023 21:02:53.481 [140244377701176] ERROR - [Req#1ae] Unknown metadata type: folder
Nov 25, 2023 21:02:56.845 [140244377701176] ERROR - [Req#1cd] Unknown metadata type: directory
Nov 25, 2023 21:02:56.852 [140244366883640] ERROR - [Req#1ce] Unknown metadata type: directory
Nov 25, 2023 21:02:57.463 [140244381920056] ERROR - [Req#1d0] Unknown metadata type: folder
Nov 25, 2023 21:02:57.474 [140244366883640] ERROR - [Req#1e0] Unknown metadata type: folder
Nov 25, 2023 21:03:10.616 [140244381920056] ERROR - Unknown metadata type: 
Nov 25, 2023 21:03:10.851 [140244366883640] ERROR - Unknown metadata type: 
Nov 25, 2023 21:03:11.016 [140244343184184] ERROR - SQLITE3:0x80000001, 26, statement aborts at 53: [select metadata_items.id as 'metadata_items_id', metadata_items.library_section_id as 'metadata_items_library_section_id', metadata_items.parent_id as 'metadata_items_parent_id', metadata_items.metadata_type as 'metadata_items_metadata_type', metadata_items.guid as 'metadata_items_guid', metadata_items.hash as 'metadata_items_hash', metadata_items.media_item_count as 'metadata_items_media_item_count', metadata_items.title as 'metadata_items_title', metadata_items.title_sort as 'metadata_items_title_sort', metadata_items.original_title as 'metadata_items_original_title', metadata_items.studio as 'metadata_items_studio', metadata_items.rating as 'metadata_items_rating', metadata_items.audience_rating as 'metadata_items_audience_rating
Nov 25, 2023 21:03:11.018 [140244343184184] ERROR - Thread: Uncaught exception running async task which was spawned by thread 140244345293624: sqlite3_statement_backend::loadOne: file is not a database
Nov 25, 2023 21:03:11.069 [140244366883640] ERROR - Unknown metadata type: 
Nov 25, 2023 21:03:16.452 [140244307323704] ERROR - [CreditsDetectionManager] BufferingLineReader: failed to read line (error: -1)
Nov 25, 2023 21:03:19.793 [140244307323704] ERROR - [CreditsDetectionManager] BufferingLineReader: failed to read line (error: -1)
Nov 25, 2023 21:03:35.517 [140244298885944] ERROR - [Req#337] Unknown metadata type: folder
Nov 25, 2023 21:04:14.484 [140244317870904] ERROR - SQLITE3:0x80000001, 26, statement aborts at 53: [select metadata_items.id as 'metadata_items_id', metadata_items.library_section_id as 'metadata_items_library_section_id', metadata_items.parent_id as 'metadata_items_parent_id', metadata_items.metadata_type as 'metadata_items_metadata_type', metadata_items.guid as 'metadata_items_guid', metadata_items.hash as 'metadata_items_hash', metadata_items.media_item_count as 'metadata_items_media_item_count', metadata_items.title as 'metadata_items_title', metadata_items.title_sort as 'metadata_items_title_sort', metadata_items.original_title as 'metadata_items_original_title', metadata_items.studio as 'metadata_items_studio', metadata_items.rating as 'metadata_items_rating', metadata_items.audience_rating as 'metadata_items_audience_rating
Nov 25, 2023 21:04:14.484 [140244317870904] ERROR - Thread: Uncaught exception running async task which was spawned by thread 140244345293624: sqlite3_statement_backend::loadOne: file is not a database
Nov 25, 2023 21:04:14.487 [140244317870904] ERROR - SQLITE3:0x80000001, 26, statement aborts at 53: [select metadata_items.id as 'metadata_items_id', metadata_items.library_section_id as 'metadata_items_library_section_id', metadata_items.parent_id as 'metadata_items_parent_id', metadata_items.metadata_type as 'metadata_items_metadata_type', metadata_items.guid as 'metadata_items_guid', metadata_items.hash as 'metadata_items_hash', metadata_items.media_item_count as 'metadata_items_media_item_count', metadata_items.title as 'metadata_items_title', metadata_items.title_sort as 'metadata_items_title_sort', metadata_items.original_title as 'metadata_items_original_title', metadata_items.studio as 'metadata_items_studio', metadata_items.rating as 'metadata_items_rating', metadata_items.audience_rating as 'metadata_items_audience_rating
Nov 25, 2023 21:04:14.488 [140244317870904] ERROR - Thread: Uncaught exception running async task which was spawned by thread 140244345293624: sqlite3_statement_backend::loadOne: file is not a database
Nov 25, 2023 21:04:14.664 [140244317870904] ERROR - SQLITE3:0x80000001, 26, statement aborts at 53: [select metadata_items.id as 'metadata_items_id', metadata_items.library_section_id as 'metadata_items_library_section_id', metadata_items.parent_id as 'metadata_items_parent_id', metadata_items.metadata_type as 'metadata_items_metadata_type', metadata_items.guid as 'metadata_items_guid', metadata_items.hash as 'metadata_items_hash', metadata_items.media_item_count as 'metadata_items_media_item_count', metadata_items.title as 'metadata_items_title', metadata_items.title_sort as 'metadata_items_title_sort', metadata_items.original_title as 'metadata_items_original_title', metadata_items.studio as 'metadata_items_studio', metadata_items.rating as 'metadata_items_rating', metadata_items.audience_rating as 'metadata_items_audience_rating
Nov 25, 2023 21:04:14.665 [140244317870904] ERROR - Thread: Uncaught exception running async task which was spawned by thread 140244345293624: sqlite3_statement_backend::loadOne: file is not a database
Nov 25, 2023 21:04:14.668 [140244317870904] ERROR - SQLITE3:0x80000001, 26, statement aborts at 53: [select metadata_items.id as 'metadata_items_id', metadata_items.library_section_id as 'metadata_items_library_section_id', metadata_items.parent_id as 'metadata_items_parent_id', metadata_items.metadata_type as 'metadata_items_metadata_type', metadata_items.guid as 'metadata_items_guid', metadata_items.hash as 'metadata_items_hash', metadata_items.media_item_count as 'metadata_items_media_item_count', metadata_items.title as 'metadata_items_title', metadata_items.title_sort as 'metadata_items_title_sort', metadata_items.original_title as 'metadata_items_original_title', metadata_items.studio as 'metadata_items_studio', metadata_items.rating as 'metadata_items_rating', metadata_items.audience_rating as 'metadata_items_audience_rating
Nov 25, 2023 21:04:14.668 [140244317870904] ERROR - Thread: Uncaught exception running async task which was spawned by thread 140244345293624: sqlite3_statement_backend::loadOne: file is not a database
Nov 25, 2023 21:04:14.717 [140244317870904] ERROR - SQLITE3:0x80000001, 11, database corruption at line 72267 of [a29f994989]
Nov 25, 2023 21:04:14.717 [140244317870904] ERROR - SQLITE3:0x80000001, 11, statement aborts at 3: [select metadata_items.id as 'metadata_items_id', metadata_items.library_section_id as 'metadata_items_library_section_id', metadata_items.parent_id as 'metadata_items_parent_id', metadata_items.metadata_type as 'metadata_items_metadata_type', metadata_items.guid as 'metadata_items_guid', metadata_items.hash as 'metadata_items_hash', metadata_items.media_item_count as 'metadata_items_media_item_count', metadata_items.title as 'metadata_items_title', metadata_items.title_sort as 'metadata_items_title_sort', metadata_items.original_title as 'metadata_items_original_title', metadata_items.studio as 'metadata_items_studio', metadata_items.rating as 'metadata_items_rating', metadata_items.audience_rating as 'metadata_items_audience_rating'
Nov 25, 2023 21:04:14.718 [140244317870904] ERROR - Thread: Uncaught exception running async task which was spawned by thread 140244345293624: sqlite3_statement_backend::loadOne: database disk image is malformed
Nov 25, 2023 21:04:14.722 [140244317870904] ERROR - SQLITE3:0x80000001, 11, database corruption at line 72267 of [a29f994989]
Nov 25, 2023 21:04:14.722 [140244317870904] ERROR - SQLITE3:0x80000001, 11, statement aborts at 3: [select metadata_items.id as 'metadata_items_id', metadata_items.library_section_id as 'metadata_items_library_section_id', metadata_items.parent_id as 'metadata_items_parent_id', metadata_items.metadata_type as 'metadata_items_metadata_type', metadata_items.guid as 'metadata_items_guid', metadata_items.hash as 'metadata_items_hash', metadata_items.media_item_count as 'metadata_items_media_item_count', metadata_items.title as 'metadata_items_title', metadata_items.title_sort as 'metadata_items_title_sort', metadata_items.original_title as 'metadata_items_original_title', metadata_items.studio as 'metadata_items_studio', metadata_items.rating as 'metadata_items_rating', metadata_items.audience_rating as 'metadata_items_audience_rating'
Nov 25, 2023 21:04:14.722 [140244317870904] ERROR - Thread: Uncaught exception running async task which was spawned by thread 140244345293624: sqlite3_statement_backend::loadOne: database disk image is malformed
Nov 25, 2023 21:04:14.737 [140244309433144] ERROR - SQLITE3:0x80000001, 11, database corruption at line 72267 of [a29f994989]
Nov 25, 2023 21:04:14.737 [140244309433144] ERROR - SQLITE3:0x80000001, 11, statement aborts at 20: [select media_items.id as 'media_items_id', media_items.library_section_id as 'media_items_library_section_id', media_items.section_location_id as 'media_items_section_location_id', media_items.metadata_item_id as 'media_items_metadata_item_id', media_items.type_id as 'media_items_type_id', media_items.width as 'media_items_width', media_items.height as 'media_items_height', media_items.size as 'media_items_size', media_items.duration as 'media_items_duration', media_items.bitrate as 'media_items_bitrate', media_items.container as 'media_items_container', media_items.video_codec as 'media_items_video_codec', media_items.audio_codec as 'media_items_audio_codec', media_items.display_aspect_ratio as 'media_items_display_aspect_ratio', m
Nov 25, 2023 21:04:14.737 [140244309433144] ERROR - Thread: Uncaught exception running async task which was spawned by thread 140244366883640: sqlite3_statement_backend::loadRS: database disk image is malformed

I’ll try the DBRepair in a bit

I’ll need help continuing with the DB repair tool. Looks like it ran into an issue and is expecting more precise commands.

root@23501a3a589d:/config# ./DBRepair.sh 
 
 
 
      Plex Media Server Database Repair Utility (Docker)
                       Version v1.01.02
 

Select

  1 - 'stop'      - Stop PMS.
  2 - 'automatic' - Check, Repair/Optimize, and Reindex Database in one step.
  3 - 'check'     - Perform integrity check of database.
  4 - 'vacuum'    - Remove empty space from database without optimizing.
  5 - 'repair'    - Repair/Optimize databases.
  6 - 'reindex'   - Rebuild database database indexes.
  7 - 'start'     - Start PMS

  8 - 'import'    - Import watch history from another database independent of Plex. (risky).
  9 - 'replace'   - Replace current databases with newest usable backup copy (interactive).
 10 - 'show'      - Show logfile.
 11 - 'status'    - Report status of PMS (run-state and databases).
 12 - 'undo'      - Undo last successful command.

 88 - 'update'    - Check for updates.
 99 - 'quit'      - Quit immediately.  Keep all temporary files.
      'exit'      - Exit with cleanup options.

Enter command # -or- command name (4 char min) : 1
 
Stopping PMS.
Stopped PMS.

Select

  1 - 'stop'      - Stop PMS.
  2 - 'automatic' - Check, Repair/Optimize, and Reindex Database in one step.
  3 - 'check'     - Perform integrity check of database.
  4 - 'vacuum'    - Remove empty space from database without optimizing.
  5 - 'repair'    - Repair/Optimize databases.
  6 - 'reindex'   - Rebuild database database indexes.
  7 - 'start'     - Start PMS

  8 - 'import'    - Import watch history from another database independent of Plex. (risky).
  9 - 'replace'   - Replace current databases with newest usable backup copy (interactive).
 10 - 'show'      - Show logfile.
 11 - 'status'    - Report status of PMS (run-state and databases).
 12 - 'undo'      - Undo last successful command.

 88 - 'update'    - Check for updates.
 99 - 'quit'      - Quit immediately.  Keep all temporary files.
      'exit'      - Exit with cleanup options.

Enter command # -or- command name (4 char min) : 2
 
Automatic Check,Repair,Index started.

Checking the PMS databases
Check complete.  PMS main database is damaged.
Check complete.  PMS blobs database is OK.

Exporting current databases using timestamp: 2023-11-25_21.17.28
Exporting Main DB
Exporting Blobs DB
Successfully exported the main and blobs databases.  Proceeding to import into new databases.
Importing Main DB.
Runtime error near line 1330: UNIQUE constraint failed: media_streams.id (19)
Runtime error near line 1331: UNIQUE constraint failed: media_streams.id (19)
Runtime error near line 1332: UNIQUE constraint failed: media_streams.id (19)
Runtime error near line 1333: UNIQUE constraint failed: media_streams.id (19)
Runtime error near line 1334: UNIQUE constraint failed: media_streams.id (19)
Runtime error near line 1335: UNIQUE constraint failed: media_streams.id (19)
Error 1 from Plex SQLite while importing from './dbtmp/library.plexapp.sql-2023-11-25_21.17.28'
Cannot continue.
Repair failed. Automatic mode cannot continue. Please repair with individual commands

Select

  1 - 'stop'      - Stop PMS.
  2 - 'automatic' - Check, Repair/Optimize, and Reindex Database in one step.
  3 - 'check'     - Perform integrity check of database.
  4 - 'vacuum'    - Remove empty space from database without optimizing.
  5 - 'repair'    - Repair/Optimize databases.
  6 - 'reindex'   - Rebuild database database indexes.
  7 - 'start'     - Start PMS

  8 - 'import'    - Import watch history from another database independent of Plex. (risky).
  9 - 'replace'   - Replace current databases with newest usable backup copy (interactive).
 10 - 'show'      - Show logfile.
 11 - 'status'    - Report status of PMS (run-state and databases).
 12 - 'undo'      - Undo last successful command.

 88 - 'update'    - Check for updates.
 99 - 'quit'      - Quit immediately.  Keep all temporary files.
      'exit'      - Exit with cleanup options.

Enter command # -or- command name (4 char min) : 5
 
Exporting current databases using timestamp: 2023-11-25_21.18.41
Exporting Main DB
Exporting Blobs DB
Successfully exported the main and blobs databases.  Proceeding to import into new databases.
Importing Main DB.
Runtime error near line 1330: UNIQUE constraint failed: media_streams.id (19)
Runtime error near line 1331: UNIQUE constraint failed: media_streams.id (19)
Runtime error near line 1332: UNIQUE constraint failed: media_streams.id (19)
Runtime error near line 1333: UNIQUE constraint failed: media_streams.id (19)
Runtime error near line 1334: UNIQUE constraint failed: media_streams.id (19)
Runtime error near line 1335: UNIQUE constraint failed: media_streams.id (19)
Error 1 from Plex SQLite while importing from './dbtmp/library.plexapp.sql-2023-11-25_21.18.41'
Cannot continue.

is your database on a local filesystem or is it running of a network location

Local

You can safely ignore the UNIQUE constraint import errors.

I thought I had that handled. I will fix it AGAIN

I can give you the manual commands (for the shell) if you’d like.

Thank you so much, I will gladly take a fix and the commands :slight_smile:

@mrjuanca

How skilled are you with Linux command line (vi / nano) / Linux graphical (gedit) text editors?

I’m looking at this problem and it will require I update the code and release a new version (a minor update but I will need to test my changes)

For you, the quick solution is to tell DBRepair.sh to ignore the error
(change the shell scripting slightly)

It will ignore the import errors (they will print but be ignored).
The utility will then verify the proper integrity of the DBs.

Does this sound viable to you?

Supplemental:

When I implemented the IgnoreErrors command line option (for cases like this), I forgot one spot :see_no_evil:

We can add the missing line and use the regular command line option as intended or manually force it.

Observe:

    # Library and blobs successfully exported, create new
    Output "Importing Main DB."
    "$PLEX_SQLITE" "$TMPDIR/$CPPL.db-REPAIR-$TimeStamp" < "$TMPDIR/library.plexapp.sql-$TimeStamp"
    Result=$?
    if ! SQLiteOK $Result; then
      Output "Error $Result from Plex SQLite while importing from '$TMPDIR/library.plexapp.sql-$TimeStamp'"
      WriteLog "Repair  - Cannot import main database from '$TMPDIR/library.plexapp.sql-$TimeStamp' - FAIL ($Result)"
      Output "Cannot continue."
      Fail=1
      return 1
    fi

    Output "Importing Blobs DB."
    "$PLEX_SQLITE" "$TMPDIR/$CPPL.blobs.db-REPAIR-$TimeStamp" < "$TMPDIR/blobs.plexapp.sql-$TimeStamp"
    Result=$?
    [ $IgnoreErrors -eq 1 ] && Result=0

    if ! SQLiteOK $Result ; then
      Output "Error $Result from Plex SQLite while importing from '$TMPDIR/blobs.plexapp.sql-$TimeStamp'"
      WriteLog "Repair  - Cannot import blobs database from '$TMPDIR/blobs.plexapp.sql-$TimeStamp' - FAIL ($Result)"
      Output "Cannot continue."
      Fail=1
      return 1
    fi

There is no [ $IgnoreErrors -eq 1 ] && Result=0 statement
between lines 884 - 885.

That’s all that’s missing.

If you look at lines 895-896, you will see the correct implementation.

My apologies for missing it

:frowning:

PS: I am updating DBRepair.sh now. I will push a new release in a few minutes. (1.01.03)

You can invoke DBRepair.sh from the command line using

./DBRepair.sh -i stop auto start exit

I will add this to the menu in the next release.

Awesome, thanks! I’m pretty comfortable with the terminal and editing files from it. But it seems I just need the new shell script? I’ll download that instead into my container.

Update:

Output:

root@563a397dacdb:/config# ./DBRepair.sh -i stop auto start exit
./DBRepair.sh: 892: Syntax error: "fi" unexpected (expecting "}")

Update 2:

Same thing on latest master branch.

root@563a397dacdb:/config# rm DBRepair.sh 
root@563a397dacdb:/config# curl https://raw.githubusercontent.com/ChuckPa/PlexDBRepair/master/DBRepair.sh -O
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 58796  100 58796    0     0   236k      0 --:--:-- --:--:-- --:--:--  237k
root@563a397dacdb:/config# chmod +x DBRepair.sh 
root@563a397dacdb:/config# ./DBRepair.sh -i stop auto start exit                                            
./DBRepair.sh: 892: Syntax error: "fi" unexpected (expecting "}")

GACK!!

Standby

Thank you and please accept my apologies.

v1.01.04 is now available.