# Bug: Adding new TV library creates many new libraries (corrupted database?)

**URL:** <https://forums.plex.tv/t/bug-adding-new-tv-library-creates-many-new-libraries-corrupted-database/858305>\
**Category:** Metadata & Adding Files\
**Tags:** server-linux, server-docker\
**Created:** [November 1, 2023, 3:15am UTC](https://forums.plex.tv/t/bug-adding-new-tv-library-creates-many-new-libraries-corrupted-database/858305 "2023-11-01T03:15:36Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrjuanca](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mrjuanca](https://forums.plex.tv/u/mrjuanca)\
**Post date:** [November 1, 2023, 3:15am UTC](https://forums.plex.tv/t/bug-adding-new-tv-library-creates-many-new-libraries-corrupted-database/858305/1 "2023-11-01T03:15:36Z")

</div>

Server Version: Latest docker image as of this writing  
Player Version: Web UI

I have some media files, managed by Sonarr. I recently added Plex as a streaming layer. I noticed the plex media server crashing with some very odd behavior. After adding the new library (of TV shows) and some scanning:

- a new media server crash report is generated
- a large amount of libraries are created with random numbers as names (no specific order). e.g. 80, 802, 331, …
- the media server crashes upon restarts etc.
- deleting the local database helps restore access

Here is the docker logs after deleting all local databases in `/Plug in Support/Databases/` and trying to re-add the library:

```auto
juanca@PLAYAPRO servarr % docker-compose up plex
[+] Building 0.0s (0/0) docker:desktop-linux
[+] Running 1/0
 ✔ Container servarr-plex-1 Created 0.0s 
Attaching to servarr-plex-1
servarr-plex-1 | [migrations] started
servarr-plex-1 | [migrations] no migrations found
servarr-plex-1 | usermod: no changes
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 | [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/2562639e-25d9-4595-119f3a8f-5fc729b8.dmp
servarr-plex-1 | Sqlite3: Sleeping for 200ms to retry busy DB.
servarr-plex-1 | Starting Plex Media Server. . . (you can ignore the libusb_init error)
servarr-plex-1 | The '--scan' operation is deprecated and will be removed in future versions of Plex Media Server.
servarr-plex-1 | Critical: libusb_init failed
^CGracefully stopping... (press Ctrl+C again to force)
Aborting on container exit...
[+] Stopping 1/1

```

And here is some snippet of the log file. I can provide the full thing upon request.

```auto
Nov 01, 2023 02:51:35.020 [140191592344376] DEBUG - Found existing show 22
Nov 01, 2023 02:51:35.021 [140191592344376] DEBUG - Added new metadata item () with ID 400
Nov 01, 2023 02:51:35.021 [140191596563256] DEBUG - [LibraryTimeline] Scanner activity on section 1: 398 added, 0 deleted
Nov 01, 2023 02:51:35.115 [140191592344376] DEBUG - Looking for path match for [/data/media/tv/One Piece/One Piece S09E52 Now Heading Towards the Blue Sea! Memories of an Interwoven Finale.mkv]
Nov 01, 2023 02:51:35.117 [140191592344376] DEBUG - Skipping hash check, no size match for 303952899 bytes.
Nov 01, 2023 02:51:35.117 [140191592344376] DEBUG - No match for hash.
Nov 01, 2023 02:51:35.117 [140191592344376] DEBUG - Found existing show 22
Nov 01, 2023 02:51:35.119 [140191592344376] DEBUG - Added new metadata item () with ID 401
Nov 01, 2023 02:51:35.120 [140191596563256] DEBUG - [LibraryTimeline] Scanner activity on section 1: 399 added, 0 deleted
Nov 01, 2023 02:51:35.190 [140191592344376] DEBUG - [Database analyze/com.plexapp.plugins.library.db] Database analyze: starting analyze (all tables)
Nov 01, 2023 02:51:35.194 [140191592344376] ERROR - [Database analyze/com.plexapp.plugins.library.db] SQLITE3:0x80000001, 11, database corruption at line 69165 of [a29f994989]
Nov 01, 2023 02:51:35.194 [140191592344376] ERROR - [Database analyze/com.plexapp.plugins.library.db] SQLITE3:0x80000001, 11, statement aborts at 1170: [analyze] database disk image is malformed
Nov 01, 2023 02:51:35.194 [140191592344376] ERROR - Native Scanner: Exception executing stage Add to Database: sqlite3_statement_backend::loadOne: database disk image is malformed
Nov 01, 2023 02:51:35.194 [140191592344376] DEBUG - Native Scanner: Executed Add to Database stage in 5.57 sec.
Nov 01, 2023 02:51:35.194 [140191592344376] DEBUG - Media Analyzer: Item 358 is already in progress.
Nov 01, 2023 02:51:35.194 [140191617657656] DEBUG - Looking for path match for [/data/media/tv/ONE PIECE (2023)/One.Piece.2023.S01E01.Romance.Dawn.1080p.NF.WEB-DL.DD+5.1.Atmos.H.264-playWEB.mkv]
Nov 01, 2023 02:51:35.195 [140191583734584] DEBUG - Media Analyzer: Performing on-the-fly analysis on 47 items.
Nov 01, 2023 02:51:35.195 [140191583734584] DEBUG - [JobRunner] Job running: FFMPEG_EXTERNAL_LIBS='/config/Library/Application\ Support/Plex\ Media\ Server/Codecs/a31c019-4614-linux-x86_64/' X_PLEX_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "/usr/lib/plexmediaserver/Plex Media Scanner" --analyze --log-file-suffix " Analysis" --no-thumbs --item 355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401
Nov 01, 2023 02:51:35.195 [140191619832632] DEBUG - Native Scanner: Executed Local Metadata stage in 0.00 sec.
Nov 01, 2023 02:51:35.195 [140191583734584] DEBUG - [JobRunner] Jobs: Starting child process with pid 656
Nov 01, 2023 02:51:35.195 [140191602891576] DEBUG - Checking descendants of The Boys
Nov 01, 2023 02:51:35.196 [140191602891576] DEBUG - Checking descendants of The Boys
Nov 01, 2023 02:51:35.196 [140191602891576] DEBUG - Checking descendants of The Boys
Nov 01, 2023 02:51:35.197 [140191602891576] DEBUG - Checking descendants of The Boys
Nov 01, 2023 02:51:35.197 [140191617657656] DEBUG - Skipping hash check, no size match for 2667555037 bytes.
Nov 01, 2023 02:51:35.197 [140191617657656] DEBUG - No match for hash.
Nov 01, 2023 02:51:35.198 [140191602891576] DEBUG - Checking descendants of The Boys
Nov 01, 2023 02:51:35.198 [140191617657656] DEBUG - Checking descendants of ONE PIECE (2023)
Nov 01, 2023 02:51:35.198 [140191602891576] DEBUG - Checking descendants of The Boys
Nov 01, 2023 02:51:35.199 [140191602891576] DEBUG - Checking descendants of The Boys
Nov 01, 2023 02:51:35.199 [140191617657656] DEBUG - Creating show 'ONE PIECE (2023)'
Nov 01, 2023 02:51:35.199 [140191602891576] DEBUG - Checking descendants of The Boys
Nov 01, 2023 02:51:35.200 [140191617657656] DEBUG - Added new metadata item (ONE PIECE (2023)) with ID 402
Nov 01, 2023 02:51:35.201 [140191596563256] DEBUG - [LibraryTimeline] Scanner activity on section 1: 400 added, 0 deleted
Nov 01, 2023 02:51:35.201 [140191617657656] DEBUG - Creating season 1 for show 'ONE PIECE (2023)'
Nov 01, 2023 02:51:35.202 [140191617657656] DEBUG - Added new metadata item () with ID 403
Nov 01, 2023 02:51:35.203 [140191596563256] DEBUG - [LibraryTimeline] Scanner activity on section 1: 401 added, 0 deleted
Nov 01, 2023 02:51:35.204 [140191617657656] DEBUG - Added new metadata item (ROMANCE DAWN) with ID 404
Nov 01, 2023 02:51:35.205 [140191596563256] DEBUG - [LibraryTimeline] Scanner activity on section 1: 402 added, 0 deleted
Nov 01, 2023 02:51:35.311 [140191617657656] DEBUG - Looking for path match for [/data/media/tv/ONE PIECE (2023)/One.Piece.2023.S01E02.The.Man.in.the.Straw.Hat.1080p.NF.WEB-DL.DD+5.1.Atmos.H.264-playWEB.mkv]
Nov 01, 2023 02:51:35.313 [140191617657656] DEBUG - Skipping hash check, no size match for 2269070499 bytes.
Nov 01, 2023 02:51:35.313 [140191617657656] DEBUG - No match for hash.
Nov 01, 2023 02:51:35.313 [140191617657656] DEBUG - Found existing show 402
Nov 01, 2023 02:51:35.315 [140191617657656] DEBUG - Added new metadata item (THE MAN IN THE STRAW HAT) with ID 405
Nov 01, 2023 02:51:35.316 [140191596563256] DEBUG - [LibraryTimeline] Scanner activity on section 1: 403 added, 0 deleted
Nov 01, 2023 02:51:35.352 [140191602891576] DEBUG - [MetadataAgent/tv.plex.agents.series] Found 1 provider matches for 'The Boys'.
Nov 01, 2023 02:51:35.352 [140191602891576] DEBUG - Scanner [Plex TV Series]: found cloud match for file '/data/media/tv/The Boys/The Boys S01E01 The Name of the Game 1080p BDrip x265 DTS-HD MA 5.1 D0ct0rLew[SEV].mkv': 'The Boys'
Nov 01, 2023 02:51:35.352 [140191602891576] DEBUG - Native Scanner: Executed Cloud Match stage in 0.16 sec.
Nov 01, 2023 02:51:35.406 [140191579515704] DEBUG - Request: [127.0.0.1:36120 (Loopback)] GET /library/changestamp (3 live) #6f1 GZIP Signed-in Token (mrjuanca)
Nov 01, 2023 02:51:35.407 [140191657057080] DEBUG - Completed: [127.0.0.1:36120] 200 GET /library/changestamp (3 live) #6f1 GZIP 0ms 417 bytes (pipelined: 1)
Nov 01, 2023 02:51:35.408 [140191617657656] DEBUG - Looking for path match for [/data/media/tv/ONE PIECE (2023)/One.Piece.2023.S01E03.Tell.No.Tales.1080p.NF.WEB-DL.DD+5.1.Atmos.H.264-playWEB.mkv]
Nov 01, 2023 02:51:35.410 [140191617657656] DEBUG - Skipping hash check, no size match for 2388859743 bytes.
Nov 01, 2023 02:51:35.410 [140191617657656] DEBUG - No match for hash.
Nov 01, 2023 02:51:35.410 [140191617657656] DEBUG - Found existing show 402
Nov 01, 2023 02:51:35.411 [140191617657656] DEBUG - Added new metadata item (TELL NO TALES) with ID 406
Nov 01, 2023 02:51:35.412 [140191596563256] DEBUG - [LibraryTimeline] Scanner activity on section 1: 404 added, 0 deleted
Nov 01, 2023 02:51:35.429 [140191579515704] DEBUG - Request: [127.0.0.1:36120 (Loopback)] GET /:/metadata/flushMetadataCounterCache?metadataItemID=22 (3 live) #836 GZIP Signed-in Token (mrjuanca)
Nov 01, 2023 02:51:35.429 [140191659166520] DEBUG - Completed: [127.0.0.1:36120] 200 GET /:/metadata/flushMetadataCounterCache?metadataItemID=22 (3 live) #836 GZIP 0ms 195 bytes (pipelined: 2)
Nov 01, 2023 02:51:35.498 [140191663930168] DEBUG - Jobs: '/usr/lib/plexmediaserver/Plex Media Scanner' exit code for process 656 is 0 (success)
Nov 01, 2023 02:51:35.498 [140191583734584] DEBUG - Killing job.
Nov 01, 2023 02:51:35.498 [140191583734584] DEBUG - Signalling job ID 656 with 9
Nov 01, 2023 02:51:35.498 [140191583734584] DEBUG - Media Analyzer: Background analysis completed in 0.3 seconds, removing 47 IDs
Nov 01, 2023 02:51:35.498 [140191592344376] DEBUG - MetadataAgentPostProcessor: adding id 354 to refresh queue (0 items in queue)
Nov 01, 2023 02:51:35.498 [140191592344376] DEBUG - Native Scanner: Executed Media Analysis stage in 0.30 sec.
Nov 01, 2023 02:51:35.526 [140191617657656] DEBUG - Looking for path match for [/data/media/tv/ONE PIECE (2023)/One.Piece.2023.S01E04.The.Pirates.Are.Coming.1080p.NF.WEB-DL.DD+5.1.Atmos.H.264-playWEB.mkv]
Nov 01, 2023 02:51:35.528 [140191617657656] DEBUG - Skipping hash check, no size match for 2602124044 bytes.
Nov 01, 2023 02:51:35.528 [140191617657656] DEBUG - No match for hash.
Nov 01, 2023 02:51:35.529 [140191617657656] DEBUG - Found existing show 402
Nov 01, 2023 02:51:35.530 [140191617657656] DEBUG - Added new metadata item (THE PIRATES ARE COMING) with ID 407
Nov 01, 2023 02:51:35.531 [140191596563256] DEBUG - [LibraryTimeline] Scanner activity on section 1: 405 added, 0 deleted
Nov 01, 2023 02:51:35.595 [140191617657656] DEBUG - Looking for path match for [/data/media/tv/ONE PIECE (2023)/One.Piece.2023.S01E05.Eat.at.Baratie.1080p.NF.WEB-DL.DD+5.1.Atmos.H.264-playWEB.mkv]
Nov 01, 2023 02:51:35.599 [140191617657656] DEBUG - Skipping hash check, no size match for 2086160414 bytes.
Nov 01, 2023 02:51:35.599 [140191617657656] DEBUG - No match for hash.
Nov 01, 2023 02:51:35.599 [140191617657656] DEBUG - Found existing show 402
Nov 01, 2023 02:51:35.601 [140191617657656] DEBUG - Added new metadata item (EAT AT BARATIE!) with ID 408
Nov 01, 2023 02:51:35.601 [140191596563256] DEBUG - [LibraryTimeline] Scanner activity on section 1: 406 added, 0 deleted
Nov 01, 2023 02:51:35.678 [140191605001016] DEBUG - Activity: registered new activity b957efbb-7165-43b3-9c25-af701b14af05 - "Updating Metadata"
Nov 01, 2023 02:51:35.681 [140191605001016] ERROR - SQLITE3:0x80000001, 11, database corruption at line 69165 of [a29f994989]
Nov 01, 2023 02:51:35.681 [140191605001016] ERROR - SQLITE3:0x80000001, 11, statement aborts at 23: [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 01, 2023 02:51:35.684 [140191605001016] DEBUG - Activity: Ended activity b957efbb-7165-43b3-9c25-af701b14af05.
Nov 01, 2023 02:51:35.686 [140191605001016] ERROR - Thread: Uncaught exception running async task which was spawned by thread 140191592344376: sqlite3_statement_backend::loadRS: database disk image is malformed
Nov 01, 2023 02:51:35.754 [140191617657656] DEBUG - Looking for path match for [/data/media/tv/ONE PIECE (2023)/One.Piece.2023.S01E06.The.Chef.and.the.Chore.Boy.1080p.NF.WEB-DL.DD+5.1.Atmos.H.264-playWEB.mkv]
Nov 01, 2023 02:51:35.756 [140191617657656] DEBUG - Skipping hash check, no size match for 2238791087 bytes.
Nov 01, 2023 02:51:35.756 [140191617657656] DEBUG - No match for hash.
Nov 01, 2023 02:51:35.757 [140191617657656] DEBUG - Found existing show 402
Nov 01, 2023 02:51:35.760 [140191617657656] DEBUG - Added new metadata item (THE CHEF AND THE CHORE BOY) with ID 409
Nov 01, 2023 02:51:35.761 [140191596563256] DEBUG - [LibraryTimeline] Scanner activity on section 1: 407 added, 0 deleted
Nov 01, 2023 02:51:35.868 [140191617657656] DEBUG - Looking for path match for [/data/media/tv/ONE PIECE (2023)/One.Piece.2023.S01E07.The.Girl.with.the.Sawfish.Tattoo.1080p.NF.WEB-DL.DD+5.1.Atmos.H.264-playWEB.mkv]
Nov 01, 2023 02:51:35.870 [140191617657656] DEBUG - Skipping hash check, no size match for 2405187510 bytes.
Nov 01, 2023 02:51:35.870 [140191617657656] DEBUG - No match for hash.
Nov 01, 2023 02:51:35.870 [140191617657656] DEBUG - Found existing show 402
Nov 01, 2023 02:51:35.872 [140191617657656] DEBUG - Added new metadata item (THE GIRL WITH THE SAWFISH TATTOO) with ID 410
Nov 01, 2023 02:51:35.873 [140191596563256] DEBUG - [LibraryTimeline] Scanner activity on section 1: 408 added, 0 deleted
Nov 01, 2023 02:51:35.934 [140191617657656] DEBUG - Looking for path match for [/data/media/tv/ONE PIECE (2023)/One.Piece.2023.S01E08.Worst.in.the.East.1080p.NF.WEB-DL.DD+5.1.Atmos.H.264-playWEB.mkv]
Nov 01, 2023 02:51:35.935 [140191617657656] DEBUG - Skipping hash check, no size match for 2087258095 bytes.
Nov 01, 2023 02:51:35.935 [140191617657656] DEBUG - No match for hash.
Nov 01, 2023 02:51:35.936 [140191617657656] DEBUG - Found existing show 402
Nov 01, 2023 02:51:35.937 [140191617657656] DEBUG - Added new metadata item (WORST IN THE EAST) with ID 411
Nov 01, 2023 02:51:35.938 [140191596563256] DEBUG - [LibraryTimeline] Scanner activity on section 1: 409 added, 0 deleted
Nov 01, 2023 02:51:36.248 [140191617657656] DEBUG - Native Scanner: Executed Add to Database stage in 1.05 sec.
Nov 01, 2023 02:51:36.248 [140191583734584] DEBUG - Media Analyzer: Performing on-the-fly analysis on 8 items.
Nov 01, 2023 02:51:36.248 [140191602891576] DEBUG - Looking for path match for [/data/media/tv/The Boys/The Boys S01E01 The Name of the Game 1080p BDrip x265 DTS-HD MA 5.1 D0ct0rLew[SEV].mkv]
Nov 01, 2023 02:51:36.248 [140191583734584] DEBUG - [JobRunner] Job running: FFMPEG_EXTERNAL_LIBS='/config/Library/Application\ Support/Plex\ Media\ Server/Codecs/a31c019-4614-linux-x86_64/' X_PLEX_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "/usr/lib/plexmediaserver/Plex Media Scanner" --analyze --log-file-suffix " Analysis" --no-thumbs --item 404,405,406,407,408,409,410,411
Nov 01, 2023 02:51:36.248 [140191592344376] DEBUG - Native Scanner: Executed Local Metadata stage in 0.00 sec.
Nov 01, 2023 02:51:36.248 [140191661275960] DEBUG - Activity: updated activity 35efaa2b-2bed-41fd-af09-6bfe5ddcea58 - completed 66.0% - Scanning TV Shows
Nov 01, 2023 02:51:36.248 [140191619832632] DEBUG - Checking descendants of The Boys
Nov 01, 2023 02:51:36.248 [140191583734584] DEBUG - [JobRunner] Jobs: Starting child process with pid 662
Nov 01, 2023 02:51:36.249 [140191661275960] DEBUG - Scanner: Processing directory /data/media/tv/The Expanse (parent: yes)
Nov 01, 2023 02:51:36.249 [140191619832632] DEBUG - Checking descendants of The Boys
Nov 01, 2023 02:51:36.250 [140191619832632] DEBUG - Checking descendants of The Boys
Nov 01, 2023 02:51:36.250 [140191619832632] DEBUG - Checking descendants of The Boys
Nov 01, 2023 02:51:36.250 [140191619832632] DEBUG - Checking descendants of The Boys
Nov 01, 2023 02:51:36.251 [140191619832632] DEBUG - Checking descendants of The Boys
Nov 01, 2023 02:51:36.251 [140191619832632] DEBUG - Checking descendants of The Boys
Nov 01, 2023 02:51:36.251 [140191602891576] DEBUG - Skipping hash check, no size match for 4989364005 bytes.
Nov 01, 2023 02:51:36.251 [140191602891576] DEBUG - No match for hash.
Nov 01, 2023 02:51:36.252 [140191619832632] DEBUG - Checking descendants of The Boys
Nov 01, 2023 02:51:36.254 [140191602891576] DEBUG - Checking descendants of The Boys
Nov 01, 2023 02:51:36.254 [140191602891576] DEBUG - Creating show 'The Boys'
Nov 01, 2023 02:51:36.257 [140191602891576] DEBUG - Added new metadata item (The Boys) with ID 412
Nov 01, 2023 02:51:36.258 [140191596563256] DEBUG - [LibraryTimeline] Scanner activity on section 1: 410 added, 0 deleted
Nov 01, 2023 02:51:36.258 [140191602891576] DEBUG - Creating season 1 for show 'The Boys'
Nov 01, 2023 02:51:36.259 [140191602891576] DEBUG - Added new metadata item () with ID 413
Nov 01, 2023 02:51:36.260 [140191596563256] DEBUG - [LibraryTimeline] Scanner activity on section 1: 411 added, 0 deleted
Nov 01, 2023 02:51:36.261 [140191661275960] DEBUG - Scanner: Processing directory /data/media/tv/The Expanse/Season 1 (parent: yes)
Nov 01, 2023 02:51:36.262 [140191602891576] DEBUG - Added new metadata item (The Name of the Game) with ID 414
Nov 01, 2023 02:51:36.262 [140191596563256] DEBUG - [LibraryTimeline] Scanner activity on section 1: 412 added, 0 deleted
Nov 01, 2023 02:51:38.424 [140191579515704] DEBUG - Request: [127.0.0.1:36128 (Loopback)] GET /library/changestamp (3 live) #835 GZIP Signed-in Token (mrjuanca)
Nov 01, 2023 02:51:38.425 [140191657057080] DEBUG - Completed: [127.0.0.1:36128] 200 GET /library/changestamp (3 live) #835 GZIP 1ms 417 bytes (pipelined: 1)
Nov 01, 2023 02:51:38.425 [140191619832632] DEBUG - [MetadataAgent/tv.plex.agents.series] Found 1 provider matches for 'The Boys'.

```

---

<div class="post-metadata">

**Author:** ![dbirch](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dbirch](https://forums.plex.tv/u/dbirch)\
**Post date:** [November 1, 2023, 3:21am UTC](https://forums.plex.tv/t/bug-adding-new-tv-library-creates-many-new-libraries-corrupted-database/858305/2 "2023-11-01T03:21:40Z")

</div>

> [@mrjuanca](#):
>
> `database disk image is malformed`

You are having database corruption, something is causing that, which in turn causes your other issues.

---

<div class="post-metadata">

**Author:** ![mrjuanca](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mrjuanca](https://forums.plex.tv/u/mrjuanca)\
**Post date:** [November 1, 2023, 3:57am UTC](https://forums.plex.tv/t/bug-adding-new-tv-library-creates-many-new-libraries-corrupted-database/858305/3 "2023-11-01T03:57:00Z")

</div>

Thanks for the quick reply.

What would be reasonable next steps to fix this?

a. Do I recreate the database?  
b. Do I inspect the library files for the offending files?

If any, how would I go about it?

Sorry big noob here :')

---

<div class="post-metadata">

**Author:** ![FordGuy61](https://avatars.discourse-cdn.com/v4/letter/f/22d042/32.png) [@FordGuy61](https://forums.plex.tv/u/FordGuy61)\
**Post date:** [November 1, 2023, 5:18am UTC](https://forums.plex.tv/t/bug-adding-new-tv-library-creates-many-new-libraries-corrupted-database/858305/4 "2023-11-01T05:18:49Z")

</div>

Run the PlexDBRepair utility.  
Use the AUTO option.  
The ReadMe has an example of running it in a Docker container.

> **[GitHub - ChuckPa/PlexDBRepair: Database repair utility for Plex Media Server...](https://github.com/ChuckPa/PlexDBRepair)**
>
> Database repair utility for Plex Media Server databases - GitHub - ChuckPa/PlexDBRepair: Database repair utility for Plex Media Server databases

---

<div class="post-metadata">

**Author:** ![mrjuanca](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mrjuanca](https://forums.plex.tv/u/mrjuanca)\
**Post date:** [November 1, 2023, 6:11am UTC](https://forums.plex.tv/t/bug-adding-new-tv-library-creates-many-new-libraries-corrupted-database/858305/5 "2023-11-01T06:11:29Z")

</div>

I ran the db repair, re-ran a library scan, same thing.

I wiped the databases, ran the db repair, re-added the library, same thing.

Seems to be a certain file? Or possibly just bad filename defaults from Sonarr?

e.g. Here is the first time an error appears:

```auto
Nov 01, 2023 05:57:03.824 [140473365887800] DEBUG - Looking for path match for [/data/media/tv/Altered Carbon/Altered.Carbon.S02E07.Experiment.Perilous.1080p.NF.WEB-DL.DDP5.1.x264-NTG.mkv]
Nov 01, 2023 05:57:03.825 [140473372613432] 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

```

---

<div class="post-metadata">

**Author:** ![mrjuanca](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mrjuanca](https://forums.plex.tv/u/mrjuanca)\
**Post date:** [November 1, 2023, 7:38am UTC](https://forums.plex.tv/t/bug-adding-new-tv-library-creates-many-new-libraries-corrupted-database/858305/6 "2023-11-01T07:38:14Z")

</div>

I tried something new. I wiped the Plex dbs. Renamed files via Sonarr to their default naming scheme. Imported the library again. Here is the first occurrence of the error.

```auto
Nov 01, 2023 07:24:55.431 [139811340184376] DEBUG - Directory had 59 files, database had 0 files, can't skip.
Nov 01, 2023 07:24:55.464 [139811271695160] DEBUG - [JobRunner] Job running: FFMPEG_EXTERNAL_LIBS='/config/Library/Application\ Support/Plex\ Media\ Server/Codecs/a31c019-4614-linux-x86_64/' X_PLEX_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "/usr/lib/plexmediaserver/Plex Media Scanner" --match --type 2 --log-file-suffix " Matcher" --item 1
Nov 01, 2023 07:24:55.464 [139811271695160] DEBUG - [JobRunner] Jobs: Starting child process with pid 639
Nov 01, 2023 07:24:55.583 [139811308776248] DEBUG - [MetadataAgent/tv.plex.agents.series] Found 1 provider matches for 'One Piece'.
Nov 01, 2023 07:24:55.583 [139811308776248] DEBUG - Scanner [Plex TV Series]: found cloud match for file '/data/media/tv/One Piece/Season 1/One Piece - S01E01 - I'm Luffy! The Man Who's Gonna Be King of the Pirates! Bluray-1080p.mkv': 'One Piece'
Nov 01, 2023 07:24:55.583 [139811308776248] DEBUG - Native Scanner: Executed Cloud Match stage in 0.21 sec.
Nov 01, 2023 07:24:55.608 [139811280276280] DEBUG - Request: [127.0.0.1:58128 (Loopback)] GET /library/changestamp (5 live) #17f GZIP Signed-in Token (mrjuanca)
Nov 01, 2023 07:24:55.609 [139811354659640] DEBUG - Completed: [127.0.0.1:58128] 200 GET /library/changestamp (5 live) #17f GZIP 0ms 416 bytes (pipelined: 1)
Nov 01, 2023 07:24:55.631 [139811245488952] DEBUG - Request: [127.0.0.1:58128 (Loopback)] GET /:/metadata/flushMetadataCounterCache?metadataItemID=1 (5 live) #1ae GZIP Signed-in Token (mrjuanca)
Nov 01, 2023 07:24:55.631 [139811352550200] DEBUG - Completed: [127.0.0.1:58128] 200 GET /:/metadata/flushMetadataCounterCache?metadataItemID=1 (5 live) #1ae GZIP 0ms 195 bytes (pipelined: 2)
Nov 01, 2023 07:24:55.699 [139811271695160] ERROR - XML: Entity: line 1:
Nov 01, 2023 07:24:55.699 [139811271695160] ERROR - XML: parser
Nov 01, 2023 07:24:55.699 [139811271695160] ERROR - XML: error :
Nov 01, 2023 07:24:55.699 [139811271695160] ERROR - XML: Start tag expected, '<' not found
Nov 01, 2023 07:24:55.700 [139811271695160] ERROR - XML: Error: sqlite3_statement_backend::loadRS: database disk image is malformed
Nov 01, 2023 07:24:55.700 [139811271695160] ERROR - XML: ^
Nov 01, 2023 07:24:55.700 [139811271695160] ERROR - Error parsing content.
Nov 01, 2023 07:24:55.703 [139811271695160] ERROR - Error parsing XML: Error parsing file.
Nov 01, 2023 07:24:55.703 [139811271695160] DEBUG - Killing job.
Nov 01, 2023 07:24:55.703 [139811271695160] DEBUG - Signalling job ID 639 with 9
Nov 01, 2023 07:24:55.715 [139811359419192] DEBUG - Jobs: '/usr/lib/plexmediaserver/Plex Media Scanner' exit code for process 639 is 0 (success)

```

I’m thinking some request is returning something other than an XML document. Would this possibly help dig into the actual cause of the bad db?

---

<div class="post-metadata">

**Author:** ![dbirch](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dbirch](https://forums.plex.tv/u/dbirch)\
**Post date:** [November 1, 2023, 9:16am UTC](https://forums.plex.tv/t/bug-adding-new-tv-library-creates-many-new-libraries-corrupted-database/858305/7 "2023-11-01T09:16:19Z")

</div>

bad XML wouldnt cause a database corruption. Odds are you are either incorrectly shutting down the server, trying to directly edit the database with an sqlite editor that isnt compatible, or have a process that is interfering with plex reading/writing the database files.

I know unraid is notorious for causing these issues.

---

<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:** [November 1, 2023, 9:30am UTC](https://forums.plex.tv/t/bug-adding-new-tv-library-creates-many-new-libraries-corrupted-database/858305/8 "2023-11-01T09:30:19Z")

</div>

An almost instant database corruption is usually caused by either

- a defective storage volume
- connecting to the storage volume (which houses the [plex data folder](https://support.plex.tv/articles/202915258-where-is-the-plex-media-server-data-directory-located/)) over a protocol which doesn’t support proper locking. e.g. CIFS
- using a file system which doesn’t support proper locking e.g. some drive pooling solutions

---

<div class="post-metadata">

**Author:** ![mrjuanca](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mrjuanca](https://forums.plex.tv/u/mrjuanca)\
**Post date:** [November 1, 2023, 6:48pm UTC](https://forums.plex.tv/t/bug-adding-new-tv-library-creates-many-new-libraries-corrupted-database/858305/9 "2023-11-01T18:48:46Z")

</div>

> [@dbirch](#):
>
> Odds are you are either (a) incorrectly shutting down the server, (b) trying to directly edit the database with an sqlite editor that isnt compatible, or (c) have a process that is interfering with plex reading/writing the database files.
> 
> I know unraid is notorious for causing these issues.

a. Possibly. I am only using `docker-compose up` and `docker-compose down`. The docker image might not have proper spin down behavior – but highly unlikely. Anyone know if that’s the case for [Docker](https://hub.docker.com/r/linuxserver/plex) ?

b. No sql editing besides deleting the database files per [https://support.plex.tv/articles/repair-a-corrupted-database/](https://support.plex.tv/articles/repair-a-corrupted-database/) article. i.e. You can also simply delete the `com.plexapp.plugins.library.db` database file while the Plex Media Server is not running

c. It’s a docker process, specifically for plex. I think it’s highly unlikey as well. But y’all might know more about common issues with the plex container.

---

<div class="post-metadata">

**Author:** ![mrjuanca](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mrjuanca](https://forums.plex.tv/u/mrjuanca)\
**Post date:** [November 1, 2023, 6:55pm UTC](https://forums.plex.tv/t/bug-adding-new-tv-library-creates-many-new-libraries-corrupted-database/858305/10 "2023-11-01T18:55:33Z")

</div>

> [@OttoKerner](#):
>
> An almost instant database corruption is usually caused by either
> 
> a. a defective storage volume  
> b. connecting to the storage volume (which houses the [plex data folder](https://support.plex.tv/articles/202915258-where-is-the-plex-media-server-data-directory-located/)) over a protocol which doesn’t support proper locking. e.g. CIFS  
> c. using a file system which doesn’t support proper locking e.g. some drive pooling solutions

a. Synology (actual storage for media) reads healthy volumes. My Mac Pro 2013 (actual `/config` storage) should be a pretty new disk – I think I bought it a couple of years ago. I can go down this path but I think the following points are more pertinent.

b. Oh! I use a network volume with CIFS for my `/data/media/...` and I use a regular volume `./plex:/config` for my container storage. Would reading the media via CIFS cause issues? The linked article seems to imply that I am not using CIFS for my config volume.

c. It’s a docker image. It runs on a Mac Pro 2013. The media is stored on a network drive. Both of these devices support Plex as standalone – but I am using docker. I would assume it would imply that the filesystem is supported. Please correct me if I’m wrong.

---

<div class="post-metadata">

**Author:** ![FordGuy61](https://avatars.discourse-cdn.com/v4/letter/f/22d042/32.png) [@FordGuy61](https://forums.plex.tv/u/FordGuy61)\
**Post date:** [November 1, 2023, 7:03pm UTC](https://forums.plex.tv/t/bug-adding-new-tv-library-creates-many-new-libraries-corrupted-database/858305/11 "2023-11-01T19:03:25Z")

</div>

Having media on a NAS with mounts via NFS or CIFS is fine.

The Plex Database must be on a local volume.

---

<div class="post-metadata">

**Author:** ![mrjuanca](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mrjuanca](https://forums.plex.tv/u/mrjuanca)\
**Post date:** [November 1, 2023, 7:05pm UTC](https://forums.plex.tv/t/bug-adding-new-tv-library-creates-many-new-libraries-corrupted-database/858305/12 "2023-11-01T19:05:37Z")

</div>

Just in case, here’s the full docker file:

> <https://github.com/juanca/servarr/blob/main/docker-compose.yaml#L53-L66>

---

<div class="post-metadata">

**Author:** ![mrjuanca](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mrjuanca](https://forums.plex.tv/u/mrjuanca)\
**Post date:** [November 1, 2023, 7:07pm UTC](https://forums.plex.tv/t/bug-adding-new-tv-library-creates-many-new-libraries-corrupted-database/858305/13 "2023-11-01T19:07:06Z")

</div>

I’d like to get more information to help debug this. I just deleted my local `./plex` directory. I am going to spin up a fresh new container. I’ll only add my movies and see if it reproduces. I am pretty sure it only happens with my TV media but let me check.

---

<div class="post-metadata">

**Author:** ![mrjuanca](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mrjuanca](https://forums.plex.tv/u/mrjuanca)\
**Post date:** [November 1, 2023, 9:27pm UTC](https://forums.plex.tv/t/bug-adding-new-tv-library-creates-many-new-libraries-corrupted-database/858305/14 "2023-11-01T21:27:44Z")

</div>

Okay, I checked the storage health on the Mac Pro 2013. Everything looked good.

Doing a full wipe (deleting all of `/config` and recreating the container) seems to have fixed the issue?

I did disable “detecting intros” and “detecting credits” to speed up debugging.

😕

I’ll add those two bits and see if it errors.

Update: Is it possible to detect intros and credits after toggling the library option? I usually takes forever (and crashes). But toggling the option seems to not detect anything in my current state.

---

<div class="post-metadata">

**Author:** ![dbirch](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dbirch](https://forums.plex.tv/u/dbirch)\
**Post date:** [November 1, 2023, 11:33pm UTC](https://forums.plex.tv/t/bug-adding-new-tv-library-creates-many-new-libraries-corrupted-database/858305/15 "2023-11-01T23:33:22Z")

</div>

Was either the container or the plex data (not your videos) on a network share?

---

<div class="post-metadata">

**Author:** ![mrjuanca](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mrjuanca](https://forums.plex.tv/u/mrjuanca)\
**Post date:** [November 2, 2023, 1:27am UTC](https://forums.plex.tv/t/bug-adding-new-tv-library-creates-many-new-libraries-corrupted-database/858305/16 "2023-11-02T01:27:15Z")

</div>

Negative. Container spun by SSHing into my Mac Pro 2013 and running the respective docker-compose. Everything (but the media) was local there.

I’m thinking the intro/outro detection was probably crashing my plex container. Crash → unexpected processes exiting → bad database processes.

If it happens again, I can try to confirm.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [January 31, 2024, 1:27am UTC](https://forums.plex.tv/t/bug-adding-new-tv-library-creates-many-new-libraries-corrupted-database/858305/17 "2024-01-31T01:27:57Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
