Plex Databases corrupted constantly

Server Version#: 1.41.3.9314
Player Version#:Any

Hi Gents.

I’m just wondering if everything is fine with these databases. Every day, I have to recover one of them, two or all three, and every night, while completing scheduled tasks I got a message “Database corrupted”.
What’s wrong with it? No errors in syslog, no disk errors (I fsck it regularly).
Any ideas please?
Thank you.

Use Chuck’s DB Repair. I’m guessing whatever you think youre doing when you recover them isn’t actually bringing back the good working version. So you’re restoring broken databases is my guess. Are you deleting the -wal files when you recover from backup? Coz they’re not supposed to be there.

Here is the link to the repair tool mentioned:

Hi, Christian. Thank you for reply.
I don’t recover from backup, I use this recommendation every time:
https://support.plex.tv/articles/repair-a-corrupted-database/
The recovering itself and followed tests finishes with “ok”

Looks like it’s scheduled tasks it selves what are breaking databases during the so-called “maintenance”…

Switched off all scheduled tasks and nor “corrupted databases”, nor “(Plex Media Scanner), jid 0, uid 972: exited on signal 11” in syslog… As they say, that’s what had to be proven. Anybody know what exactly do these “scheduled tasks”? What does mean, for example, “Optimize database every week”, “Upgrade media analysis during maintenance” and so on?

scheduled tasks are those tasked PMS runs at night (default is 02 → 05 am)

Database optimization is a simple sqlite VACUUM command to compact it.

Upgrading media analysis means that it will look for newly added media and reanalyze anything not scanned in a while (if media changed).

I usually turn that off. My media is static (don’t change after loading)
I usually turn off most of the other things.

These work well for me. Plus, my machine is on a UPS to prevent power issues from corrupting the DB.

I can’t speak to freebsd nor do I know if my script tool works there.

I ‘PRAGMA integrity_check’, ‘VACUUM’ and ‘REINDEX’ databases using cron every night. And I don’t understand why Plex Scanner started by Scheduled Tasks every time crashes (Just a few minutes later 2 am). Everything is fine when I start it manually.

@christian_kent_drools

Cool work on the HostConfig.
I’d recommend you further refine that to ensure the host is BSD
– Is there a default location for AppSuppDir or a common place to find it?

Please remember, there are limits to what the tool can fix.
Its primary purpose is to fix malformed DB files (the physical DB is damaged).
It cannot fix content errors (failed migrations, etc)

Look in your databases folder where the DB’s are.

Are there any old backups (or do you have saved backups somewhere) ?

When the data in the records is corrupted, there’s nothing which can be done except :

  1. Stop PMS
  2. Delete the WAL and SHM files (do they don’t corrupt the new DB you’ll use)
  3. Now copy the backup DB to take the place (copy over) the damaged on.
  4. Start PMS

When you run your nightly backups, do you stop Plex Media Server first, then perform the backup, and then restart PMS? I ask because attempting to restore from a database backed up without doing so can lead to corruption (for at least a couple of reasons).

There is no documentation about the DB.

Even with my knowledge and access, it’s too complex for me to fully understand all the relationships. Only the engineering team really knows all the details.

I can offer you my DB tool which helps keep what you have in the best possible form. It cleans out deleted records and will optimize the DB as well as rebuild indexes,

You’re welcome to read the documentation I have for it and use it if you want.

In general, folks usually find that:

  1. Auto optimization works the best for most cases
  2. Pruning & purging old temp files from PMS helps manage the fileystem bloat.
  3. Should you need to restore a DB from one of Plex’s backups, it ensures that the incoming DB isn’t corrupted (at the DB level) and manages PMS to ensure you don’t get a bad DB during the restore process (Process control)

lol I knew it. Like I said you’re restoring broken databases. That was my first comment.

If, at some point, you restored from your “nightly” backup (that is essentially a borked database), then all your backups thereafter are also borked.

You want a solution to fix your problem? There isn’t any. Your problem is that you don’t understand what everyone is telling you. There’s no way to fix the content now that it’s in that state. The guy who wrote the DB Repair script just told you that even he can’t fix that. If his script can’t fix your database, it means you gotta start from scratch.

You can’t just copy an active database.

The Database contents are corrupt (Damaged)

My tool can only fix the SQLite database structure.
It is a shell script. It can’t interpret the contents of each record, or a set of records, in a database and figure out what’s wrong
(My tool is 2,362 lines line compared to the 400,000+ lines of code in PMS)

This really is one of those situations where you have to start over.

WITH THAT SAID – If you have cloud sync enabled to retain your watch history, when you do start over, PMS will retrieve your watch history for your media.

For future planning.

  1. Put custom posters you want to use in with the media (and enable the “Local Media Assets” agent)
  2. Stop the DB before backups or any other database operations
    – ONLY PMS can backup its database while running BECAUSE it owns the DB AND it locks the DB while making the backup so that no records can be changed.

I told you, what Plex is backing up is a corrupted database. This is why despite your pronunciations that you know about databases, I don’t believe it. This logic is so basic. It feels like I’m talking to a child. Read what I said before:

I’m trying to help you, but since my help doesn’t fix your problem, you think that I’m not trying to help you. Very well, wallow in your own misery. Have fun.

Thanks, Chuck

At least you were helpful, unlike someone else on this forum :slight_smile:

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