Since there were only 307 rows, I simply sorted the version column and eyeballed for duplicate rows in that field in the schema_migrations table.
Sure enough, I found a duplicate. See attached screenshot schema_migrations_dupe.png showing the unsorted table. The duplicates both had no values in the other columns, so effectively represented something that was likley very safe to remove one of.
I wrote the change, then moved the db file back onto my server (headless) overwritting the old db. But when I started it back up, the GUI did not start. I already had an idea of what was next, and went directly to remove some 20 rows in the version column with values like 500000000000 and 500000000001, which seemed odd, as they were the only rows that did not follow the YYYYMMDDTT.XX format. I figured perhaps these were also corrupt in some way, noting they contained SQL commands related to the fts4_xxx table referenced in my other UNIQUE constraint error.
Moving the db back onto the server after the 2nd edit and restarting yeilded a working web page. On further inspection, it looks like the server started stepping through migrations on each subsequent restart. Here are my last 5 restarts (default log depth) during the move over of my two db changes.
#5 and #4 were both just restarts of the current version w/ the Db error - I now realize it was stuck doing the migration 202210260000 when it hit the error previously. I believe now, looking back, that it was just the logging of the migration that failed, due to the index problem.
May 22, 2023 11:50:18.017 [139695918926648] INFO - Plex Media Server v1.32.1.6999-91e1e2e2c - Debian GNU/Linux PC x86_64 - build: linux-x86_64 debian - GMT -04:00
..
May 22, 2023 11:50:18.147 [139695998675600] INFO - Running migrations. (EPG 0)
May 22, 2023 11:50:18.150 [139695998675600] INFO - Running forward migration 202210260000.
May 22, 2023 11:50:18.162 [139695998675600] ERROR - SQLITE3:0x80000001, 779, index corruption at line 94622 of [a29f994989]
#3 looks like it was stuck in a migration script loop, repeating a small set of scripts after my first DB edit and downgrading back to the working 1.30.0; Possibly I could have actually just restarted it again and again here without removing the second set of 5000000000X entries. I note the down migration possibly indicating it is downgrading the schema due to my moving back to 1.30 from 1.32.
May 22, 2023 12:17:04.686 [0x7ff5735fcb38] INFO - Plex Media Server v1.30.0.6486-629d58034 - Debian GNU/Linux PC x86_64 - build: linux-x86_64 debian - GMT -04:00
…
May 22, 2023 12:17:04.754 [0x7ff5771fc0d0] INFO - Running migrations. (EPG 0)
May 22, 2023 12:17:04.775 [0x7ff5771fc0d0] INFO - SQLITE3:0x80000001, 283, recovered 23 frames from WAL file /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plu
g-in Support/Databases/com.plexapp.plugins.library.blobs.db-wal
May 22, 2023 12:17:04.779 [0x7ff5771fc0d0] INFO - Running migrations. (EPG 0)
May 22, 2023 12:17:04.780 [0x7ff5771fc0d0] INFO - Running down migration 202212022300.031.
May 22, 2023 12:17:04.781 [0x7ff5771fc0d0] INFO - Completed down migration 202212022300.031.
May 22, 2023 12:17:04.781 [0x7ff5771fc0d0] INFO - Running down migration 202212022300.021.
May 22, 2023 12:17:04.781 [0x7ff5771fc0d0] INFO - Completed down migration 202212022300.021.
May 22, 2023 12:17:04.781 [0x7ff5771fc0d0] INFO - Running down migration 202212022300.011.
May 22, 2023 12:17:04.782 [0x7ff5771fc0d0] INFO - Completed down migration 202212022300.011.
May 22, 2023 12:17:04.782 [0x7ff5771fc0d0] INFO - Running down migration 202212022300.
May 22, 2023 12:17:04.782 [0x7ff5771fc0d0] INFO - Analyzing database.
May 22, 2023 12:17:04.786 [0x7ff5771fc0d0] INFO - Vacuuming database.
May 22, 2023 12:17:08.173 [0x7ff5771fc0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 12:17:08.176 [0x7ff5771fc0d0] INFO - Completed down migration 202212022300.
May 22, 2023 12:17:08.176 [0x7ff5771fc0d0] INFO - Running down migration 202212022200.031.
May 22, 2023 12:17:08.182 [0x7ff5771fc0d0] INFO - Completed down migration 202212022200.031.
May 22, 2023 12:17:08.182 [0x7ff5771fc0d0] INFO - Running down migration 202212022200.021.
May 22, 2023 12:17:08.183 [0x7ff5771fc0d0] INFO - Completed down migration 202212022200.021.
May 22, 2023 12:17:08.183 [0x7ff5771fc0d0] INFO - Running down migration 202212022200.011.
May 22, 2023 12:17:08.184 [0x7ff5771fc0d0] INFO - Completed down migration 202212022200.011.
May 22, 2023 12:17:08.184 [0x7ff5771fc0d0] INFO - Running down migration 202212022200.
May 22, 2023 12:17:08.185 [0x7ff5771fc0d0] INFO - Analyzing database.
May 22, 2023 12:17:08.190 [0x7ff5771fc0d0] INFO - Vacuuming database.
May 22, 2023 12:17:10.395 [0x7ff5771fc0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
#2 - I believe this was just another restart in my sequence of testing for the web UI availability
May 22, 2023 12:34:20.154 [0x7f30187fcb38] INFO - Plex Media Server v1.30.0.6486-629d58034 - Debian GNU/Linux PC x86_64 - build: linux-x86_64 debian - GMT -04:00
May 22, 2023 12:34:20.154 [0x7f30187fcb38] INFO - Linux version: 12 (bookworm), language: en-US
May 22, 2023 12:34:20.155 [0x7f30187fcb38] INFO - Processor: 14-core Intel(R) Xeon(R) CPU E5-2660 v4 @ 2.00GHz
May 22, 2023 12:34:20.155 [0x7f30187fcb38] INFO - Compiler is - Clang 11.0.1 (https://plex.tv 9b997da8e5b47bdb4a9425b3a3b290be393b4b1f)
May 22, 2023 12:34:20.155 [0x7f30187fcb38] INFO - /usr/lib/plexmediaserver/Plex Media Server
May 22, 2023 12:34:20.176 [0x7f301d5440d0] INFO - [CERT/OCSP] Successfully retrieved response from cache.
May 22, 2023 12:34:20.223 [0x7f301d5440d0] INFO - Running migrations. (EPG 0)
May 22, 2023 12:34:20.248 [0x7f301d5440d0] INFO - Running migrations. (EPG 0)
May 22, 2023 12:34:22.130 [0x7f301512cb38] INFO - LibraryUpdateManager path watching is disabled
May 22, 2023 12:34:25.004 [0x7f301d5440d0] WARN - [DatabaseFixups] Held transaction for too long (/data/jenkins/server/3521777883/Library/DatabaseFixups.cpp:358): 0.310000 seconds
May 22, 2023 12:34:27.067 [0x7f3015e6bb38] WARN - [MediaProviderManager] Unrecognized MediaProvider feature: availability
May 22, 2023 12:34:27.067 [0x7f3015e6bb38] WARN - [MediaProviderManager] Unrecognized MediaProvider feature: availability-platforms
May 22, 2023 12:34:27.132 [0x7f3013443b38] WARN - [MediaProviderManager] Unrecognized MediaProvider feature: availability
May 22, 2023 12:34:27.132 [0x7f3013443b38] WARN - [MediaProviderManager] Unrecognized MediaProvider feature: availability-platforms
May 22, 2023 12:34:33.235 [0x7f3013977b38] WARN - [Req#6e] QueryParser: Invalid field ‘sectionID’ found, ignoring.
May 22, 2023 12:34:33.337 [0x7f3013977b38] WARN - [Req#6e] SLOW QUERY: It took 380.000000 ms to retrieve 50 items.
May 22, 2023 12:34:58.828 [0x7f3012a2cb38] WARN - [Req#f8] QueryParser: Invalid field ‘sectionID’ found, ignoring.
May 22, 2023 12:34:58.934 [0x7f3012a2cb38] WARN - [Req#f8] SLOW QUERY: It took 300.000000 ms to retrieve 50 items.
May 22, 2023 12:35:01.293 [0x7f30179d6b38] ERROR - MetadataAgentPostProcessor: failed to find agent for identifier com.plexapp.agents.imdb
#1 Right before my last restart, it is still running more migrations, but the database has not been changed by me. Here is when I actually notice some of these logs are “down migrations” whereas some are “forward migrations”.
May 22, 2023 14:51:26.170 [0x7f78661fcb38] INFO - Plex Media Server v1.30.0.6486-629d58034 - Debian GNU/Linux PC x86_64 - build: linux-x86_64 debian - GMT -04:00
May 22, 2023 14:51:26.171 [0x7f78661fcb38] INFO - Linux version: 12 (bookworm), language: en-US
May 22, 2023 14:51:26.171 [0x7f78661fcb38] INFO - Processor: 14-core Intel(R) Xeon(R) CPU E5-2660 v4 @ 2.00GHz
May 22, 2023 14:51:26.171 [0x7f78661fcb38] INFO - Compiler is - Clang 11.0.1 (https://plex.tv 9b997da8e5b47bdb4a9425b3a3b290be393b4b1f)
May 22, 2023 14:51:26.171 [0x7f78661fcb38] INFO - /usr/lib/plexmediaserver/Plex Media Server
May 22, 2023 14:51:26.193 [0x7f786aeaa0d0] INFO - [CERT/OCSP] Successfully retrieved response from cache.
May 22, 2023 14:51:26.239 [0x7f786aeaa0d0] INFO - Running migrations. (EPG 0)
May 22, 2023 14:51:26.243 [0x7f786aeaa0d0] INFO - Running forward migration 20210922132300.
May 22, 2023 14:51:26.266 [0x7f786aeaa0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 14:51:26.270 [0x7f786aeaa0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 14:51:26.273 [0x7f786aeaa0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 14:51:26.277 [0x7f786aeaa0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 14:51:26.281 [0x7f786aeaa0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 14:51:26.285 [0x7f786aeaa0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 14:51:26.288 [0x7f786aeaa0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 14:51:26.290 [0x7f786aeaa0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 14:51:26.293 [0x7f786aeaa0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 14:51:26.295 [0x7f786aeaa0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 14:51:26.297 [0x7f786aeaa0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 14:51:26.299 [0x7f786aeaa0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 14:51:26.302 [0x7f786aeaa0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 14:51:26.304 [0x7f786aeaa0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 14:51:26.306 [0x7f786aeaa0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 14:51:26.308 [0x7f786aeaa0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 14:51:26.311 [0x7f786aeaa0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 14:51:26.313 [0x7f786aeaa0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 14:51:26.315 [0x7f786aeaa0d0] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 14:51:26.317 [0x7f786aeaa0d0] INFO - Completed forward migration 20210922132300.
May 22, 2023 14:51:26.354 [0x7f786aeaa0d0] INFO - Running migrations. (EPG 0)
#In my last / current iteration I upgraded to the current version and sure enough more migrations happen AND it seems to be running migration scripts related to the 50000000X rows I deleted. It would seem in fixing this DB that is was a mere log, and not the source for all the migration scripts which all seem to have been applied now, errors or not.
May 22, 2023 16:01:58.791 [140406092188472] INFO - Plex Media Server v1.32.1.6999-91e1e2e2c - Debian GNU/Linux PC x86_64 - build: linux-x86_64 debian - GMT -04:00
May 22, 2023 16:01:58.792 [140406092188472] INFO - Linux version: 12 (bookworm), language: en-US
May 22, 2023 16:01:58.792 [140406092188472] INFO - Processor: 14-core Intel(R) Xeon(R) CPU E5-2660 v4 @ 2.00GHz
May 22, 2023 16:01:58.792 [140406092188472] INFO - Compiler is - Clang 11.0.1 (https://plex.tv 9b997da8e5b47bdb4a9425b3a3b290be393b4b1f)
May 22, 2023 16:01:58.792 [140406092188472] INFO - /usr/lib/plexmediaserver/Plex Media Server
May 22, 2023 16:01:58.875 [140406152133264] INFO - [CERT/OCSP] Successfully retrieved response from cache.
May 22, 2023 16:01:58.920 [140406152133264] INFO - Running migrations. (EPG 0)
May 22, 2023 16:01:58.923 [140406152133264] INFO - Running forward migration 500000000000.
May 22, 2023 16:01:59.100 [140406152133264] WARN - Held transaction for too long (/data/jenkins/server/3528069351/Library/DatabaseMigrations.cpp:291): 0.180000 seconds
May 22, 2023 16:01:59.222 [140406152133264] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 16:01:59.226 [140406152133264] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
May 22, 2023 16:01:59.230 [140406152133264] INFO - SQLITE3:0x80000001, 17, statement aborts at 58: [select * from metadata_items limit 1] database schema has changed
All to say, I am up and running again on my original database, with the current Debian PMS packages and passing integrity tests
media:/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases# /usr/lib/plexmediaserver/Plex\ SQLite /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Plug-in\ Support/Databases/com.plexapp.plugins.library.db
SQLite version 3.39.4 2022-09-29 15:55:41
Enter “.help” for usage hints.
sqlite> PRAGMA integrity_check;
ok
It is worth noting that I discovered older copies of my DB (2020, 2021) in the same directory as my database, presumably created by the Debian install script or Plex during significant db schema changes that may not be downgradable. I had not searched very hard, as one of the functions of the PlexDBRepair tool is to look for and/or try restoring backups → but it must be in a different context to these ones I found as it was able to find my db automatically, but not these backups in the same folder.
-rw-r–r-- 1 plex plex 151770112 May 22 16:02 com.plexapp.plugins.library.db
-rw-r–r-- 1 plex plex 539601920 Dec 28 2020 com.plexapp.plugins.library.db-2020-12-28
-rw-r–r-- 1 plex plex 541475840 Dec 31 2020 com.plexapp.plugins.library.db-2020-12-31
-rw-r–r-- 1 plex plex 540361728 Jan 3 2021 com.plexapp.plugins.library.db-2021-01-03
-rw-r–r-- 1 plex plex 540453888 Jan 6 2021 com.plexapp.plugins.library.db-2021-01-06