Skip to content

Plex Database Corruption — Complete Guide

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about Plex Database Corruption. We cover key concepts, practical examples, and best practices.

Hook

Plex starts up, scans for 10 seconds, then crashes. The logs say "database disk image is malformed." Your entire library, metadata, watch history, and playlists suddenly vanish. Database corruption is rare but devastating when it hits.

The Wrong Way

Some users immediately restore a week-old backup or delete com.plexapp.plugins.library.db and rescan everything. You lose all watch states, ratings, and collections.

# BAD: Blindly deleting the database
rm -f "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db"
Library empty — rescanning 35,000 items
All watch history lost
All user ratings lost

A full rescan from scratch works, but you lose years of accumulated metadata, collections, and play history.

The Right Way

Plex keeps automatic backups. Restore the most recent uncorrupted backup, then run integrity checks.

# 1. Stop Plex
sudo systemctl stop plexmediaserver

# 2. Navigate to the databases directory
cd "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/"

# 3. List backups
ls -la com.plexapp.plugins.library.db-*

# 4. Test each backup with sqlite3
for f in com.plexapp.plugins.library.db-*; do
  sqlite3 "$f" "PRAGMA integrity_check;" && echo "$f is clean"
done
com.plexapp.plugins.library.db-20260620 clean
com.plexapp.plugins.library.db-20260619 clean
# 5. Restore the clean backup
cp com.plexapp.plugins.library.db-20260620 com.plexapp.plugins.library.db
chown plex:plex com.plexapp.plugins.library.db

# 6. Start Plex
sudo systemctl start plexmediaserver

If no backup is clean, try sqlite3 old.db "VACUUM;" or .recover to salvage data.

Prevention

  • Plex auto-backups run daily; keep at least 7 days of backups.
  • Do not hard-stop Plex (kill -9) — always shut down gracefully.
  • Run Plex on a filesystem that supports atomic writes (ext4, ZFS, Btrfs).
  • Monitor the Plex log for database or sqlite warnings.
  • Consider a nightly sqlite3 library.db ".backup library.db.bak" cron job.

Advanced Troubleshooting

Check the Logs

Most TOOL errors are logged to stdout or a dedicated log file. Check your logs first:

# Check system logs
journalctl -u tool --since "1 hour ago"

# Or check the application log
tail -50 ~/.tool/logs/error.log

Test with a Minimal Example

Create the simplest possible tool configuration to verify the base setup works:

tool --version
tool --help

If the minimal test passes, add configuration options one at a time until you find the breaking change.

Common Configuration Mistakes

  • Using the wrong file path or URL in configuration
  • Forgetting to restart TOOL after changing config files
  • Mixing tabs and spaces in YAML configuration files
  • Setting incorrect permissions on configuration directories

When to Reinstall

If none of the above resolves the issue, consider a clean reinstall:

# Backup your configuration
cp -r ~/.tool ~/.tool.bak

# Remove and reinstall
# Follow the official TOOL installation guide

This ensures you start from a known good state and can isolate the issue.

Common Mistakes with database corrupt

  1. Misunderstanding that String is [Char] with poor performance for large text operations
  2. Using foldl instead of foldl' causing stack overflow on large lists
  3. Forgetting deriving (Show, Eq) on custom data types needed for debugging

These mistakes appear frequently in real-world PLEX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

How often does Plex backup the database?

By default, every 24 hours during the scheduled maintenance window. Backups are stored in the same directory as the live database with a date suffix.

Can a power loss corrupt the database?

Yes. SQLite is resilient but not immune to power loss. Use a UPS on your server and set PRAGMA journal_mode=WAL for better crash recovery (Plex uses WAL by default on recent versions).

What if the backup is also corrupted?

Stop Plex immediately, copy the database files to a safe location, and use sqlite3 broken.db ".recover" | sqlite2 recovered.db. You may lose some recent changes but the bulk of your library will survive.


DodaTech — protect your media library's memory.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro