DBRepair development

@Tony_T

My DB was pristine.

Today , running 1.42.2, it shows corrupted.

This is a PMS issue. Hacking the DB won’t resolve the problem.

I’ve chatted with FordGuy who will take to Plex.

Notice the specific indexes which now show failed on 1.42.2

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

Checking FTS (Full-Text Search) indexes
DEBUG:  Status = Error: stepping, database disk image is malformed (11)
  FTS index 'fts4_metadata_titles' - DAMAGED
    Error: Error: stepping, database disk image is malformed (11)
DEBUG:  Status = Error: stepping, database disk image is malformed (11)
  FTS index 'fts4_metadata_titles_icu' - DAMAGED
    Error: Error: stepping, database disk image is malformed (11)
DEBUG:  Status = Error: stepping, database disk image is malformed (11)
  FTS index 'fts4_tag_titles' - DAMAGED
    Error: Error: stepping, database disk image is malformed (11)
DEBUG:  Status = Error: stepping, database disk image is malformed (11)
  FTS index 'fts4_tag_titles_icu' - DAMAGED
    Error: Error: stepping, database disk image is malformed (11)
  FTS index 'fts4_metadata_titles' (blobs) - OK
  FTS index 'fts4_metadata_titles_icu' (blobs) - OK
  FTS index 'fts4_tag_titles' (blobs) - OK
  FTS index 'fts4_tag_titles_icu' (blobs) - OK
FTS integrity check complete. One or more FTS indexes are DAMAGED.
Use 'reindex' command (option 6) or 'automatic' (option 2) to rebuild.

NOTE: FTS indexes are damaged but main database structure is OK.
      Use 'reindex' (option 6) or 'automatic' (option 2) to rebuild.

Not sure that I’d call it hacking the Database by having the Plex Sqlite remove the “bad” FTS Tables and have Plex reload them.
DBRepair reports no errors now.

Seriously, what in what I posted do you see as hacking the db?

“hacking” in this context (to me) means:

  • Delete the SHM / WAL. — which is anything not committed to the DB file
    – you don’t know which records are in and which aren’t. Metadata can easy get ouit of sync

Please understand, my opinion doesn’t matter anymore.

If DBRepair is doing the wrong thing, I’ll fix what I can or just remove the FTS code entirely. It was added recently to address problems with Collections and Playlists. If it’s doing more harm then good — It’s outta there.

Your opinion DOES matter.
I knew when I first posted this issue that it was a Plex Issue (not DBRepair) and IIRC, said so.
The FTL code is useful as it identified a PLEX problem in my database that I didn’t know existed, that you made the Plex Team aware of.

Deleting the SHM / WAL was not necessary for me as it’s “gone” with sudo systemctl stop plexmediaserver (I debated leaving that out of my write-up)

Having had a look at the sqlite3 docs a bit regarding how the integrity check of the FTS4 tables is being done in DBrepair.sh, I found this:

(See section 7.3)

That section outlines the means by which an integrity check is performed on a virtual table (e.g. the ‘fts4’ tables in the PMS DBs). The failure modes are described. The second one is:

  • Using the FTS4 content option and failing to manually keep the content in sync with the FTS4 inverted indices.

I’m guessing that’s the failure mode being triggered. I assume that the database is reindexed occasionally as part of normal PMS background maintenance activities, but there are times when the metadata_items (from which fts4_metadata_titles is created) and fts4_metadata_titles become out of sync.

Any failure of the table integrity check returns a SQLITE_CORRUPT error, regardless of the failure mode (even if the database isn’t really corrupt).

This is mostly supposition, based on the docs (and how the fts4 virtual tables are created).

It’s interesting reading. I’d recommend reading the intro to section 7, plus the sections for the ‘integrity-check’ and ‘rebuild’ commands, for anyone interested.


For what it’s worth, here’s how the fts4_metadata_titles table is created in the PMS DB schema:

CREATE VIRTUAL TABLE fts4_metadata_titles USING fts4(content=‘metadata_items’, title, title_sort, original_title)

So, it’s populated from the title, title_sort, and original_title columns of the metadata_items table.

While no errors yesterday (tested more than a few times), this morning the errors returned.

As @ChuckPa has said “This is a PMS issue. I’ve chatted with FordGuy who will take to Plex.” I’ll just have to wait and see if Plex fixes this issue.

Checking FTS (Full-Text Search) indexes

FTS index ‘fts4_metadata_titles_icu’ - DAMAGED

Error: Error: stepping, database disk image is malformed (11)

FTS index ‘fts4_tag_titles_icu’ - DAMAGED

Error: Error: stepping, database disk image is malformed (11)

FTS index ‘fts4_metadata_titles_icu’ (blobs) - OK

FTS index ‘fts4_tag_titles_icu’ (blobs) - OK

FTS integrity check complete. One or more FTS indexes are DAMAGED.

Use ‘reindex’ command (option 6) or ‘automatic’ (option 2) to rebuild.

I messaged one of the developers, referencing this thread and some tests I ran on my own server.

They filed an issue to investigate what is happening with the db, what DBRepair is seeing, etc.

That’s all the info I have right now. I’ll update if I hear anything, and Plex devs can obviously post updates themselves as needed.

ALL:

First, Hi. :waving_hand:
I’m doing ok so far.

Second, which I think you’ll all like,

DBRepair 2.0.0 development underway.

  • Written in C
  • No external dependencies (Runtime libraries - Static linked))
    – It’ll run anywhere PMS can be installed
  • If it doesn’t look totally cheesy, it’ll have a TUI interface.
    – Function key or Letter key input in interactive mode
    – Popup windows in the main display area

For those of you who remember the old DOS days and “Norton SpeedDisk”,
It’ll look like that but the graphics characters are so much better now.

I’ll have the MacOS version first (ARMv8) then will do the CLANG cross-compile to other platforms. (CLANG21).

The source is much cleaner now. 3200 lines and counting but compiled is less than the 70 KB DBRepair.sh is.

I’ll keep everyone updated as I get closer to needing help testing.

Hope all is well otherwise.

Chuck, this is the stuff legends are made of :+1:

And the Windows version is on its way too? :grinning_face:

I don’t know if it will cross-compile to Windows but if it will then. YES

NOTE:

Yes, Clang 21 will cross-compile to Windows 11. Clang/LLVM is designed as a native cross-compiler, meaning a single installation can target different operating systems and architectures (x86_64 or ARM64) by specifying the target triple.

[image]mcilloni.ovh +3

While earlier versions already supported this, Clang 21 will continue to support targeting Windows 11 (MSVC ABI) from host environments like Linux, macOS, or other Windows systems.

GitHubGitHub +1

I’ll only need pathname / configuration detection info so it knows where to look on a Windows machine.

Quick Question –

Am I correct that DBRepair.sh does not currently support the new Plex MacOS configuration ?

I’m running into trouble with detection in C.
I tried the shell script version and found it doesn’t detect it either.

Can anyone confirm ?

Secondary question:

Can I move my ~/Library/Application Support/Plex Media Server directory off to another (disposable) SSD ?

DBRepair.sh seems to work fine in my environment (macOS 15.7.4, PMS 1.41.1.10611). I didn’t test all functions, but stop, start, check, automatic, status, and exit all work as expected.

Yes, but you’ll need to go old-school (using a symbolic link from the expected/normal location to the real location).
~/Library/Application Support/Plex Media Server —> /Volumes/DisposableSSD/Plex Media Server.

I actually did this for a while and it worked fine (I’ve not redirected my Plex data folder this way in a while though).

@pshanew

Where is Plex Media Server.app ?

Is it in /Applications or is it in ~/Applications (your home directory) ?

It’s in /Applications.

Thanks. That explains why it works & fails.

The existing code looks for /Applications.

I was unaware Plex had moved to /Users/chuck/Applications. (e.g ~/Applications)

I need update the code for new/fresh PMS installations. :roll_eyes:

I was unaware of this as well. The installation docs just say to (manually) move Plex Media Server.app to “Applications”:
https://support.plex.tv/articles/200288586-installation/#toc-1

Did you do the installation method where you downloaded it to Downloads and ran it from there, and it moved itself to ~/Applications?

For me, It offered to move itself to /Applications.
I wasn’t worried…

BUT… it failed to do so

Can I move the Metadata directory (symlink) to an external SSD ?

Yes, you can symlink across volumes as long as the filesystems involved support it (APFS, HFS+). Be wary of permissions :wink: .

It’s already APFS and “I own it” :slight_smile:
I don’t want to burn out the integrated SSD because of PMS
I’d rather replace a cheap SSD.

I’m loving this mini. DAMN FAST!