I noticed that from time to time the Plex Media Server saves several times the same (exact) file path in the media_parts table. How can this happen and is there a way to clean this up? A media library rescan did not delete them.
Here is a screenshot from the database, the hash is identical:
With the following SQL query I optimized the whole thing to find the matching entries.
SELECT file, COUNT(*) as count FROM media_parts GROUP BY media_item_id HAVING COUNT(*) > 1
If I were to delete the entries from the media_parts table, are there any other relations to consider? At least in the “media_item” table there seems to be an entry. Is it enough to delete the two contiguously?
This is evident not only in the database but also in the Web UI.
I have now calmly looked at the database and built a query with which you can display all affected rows and delete them.
For me it solved the duplicate indexing issues considering possible parts, so I validate the “meta_item_id” as well as the file path. But it’s best to make a backup before!
1. Find (to be sure):
SELECT * FROM media_parts AS a WHERE a.id < (SELECT MAX(id) FROM media_parts AS b WHERE a.media_item_id = b.media_item_id AND a.file = b.file GROUP BY media_item_id HAVING COUNT(*) > 1)
2. Delete:
DELETE FROM media_parts AS a WHERE a.id < (SELECT MAX(id) FROM media_parts AS b WHERE a.media_item_id = b.media_item_id AND a.file = b.file GROUP BY media_item_id HAVING COUNT(*) > 1)
It is usually caused by more than one library scan running simultaneously.
e.g. a “periodic” scan and an “automatic” scan coinciding, or a manually triggered scan coinciding with a periodic scan etc.
Unfortunately not that I know.
It is best to disable automatic scans if you use periodic ones.
Disable both if you usually trigger a library scan manually after adding new media.