Change library ID

So, I accidentally deleted the wrong library. Yes, I’m an idiot. I immediately re-added the library and luckily Plex remembered all watched states. Lucky me!

Not so lucky, the library had ID 3… but the new one has ID 30. So now, instead of being the second library, it’s the last one. And I’d really like it if I could change the order back. So, I backed up my database, copied it to my laptop and opened it up in an SQlite editor. Found all tables with a library_section_id column that actually had any data in it and eventually ran these queries:

UPDATE directories SET library_section_id = 3 WHERE library_section_id = 30;
UPDATE library_section_permissions SET library_section_id = 3 WHERE library_section_id = 30;
UPDATE library_timeline_entries SET library_section_id = 3 WHERE library_section_id = 30;
UPDATE media_items SET library_section_id = 3 WHERE library_section_id = 30;
UPDATE media_part_settings SET library_section_id = 3 WHERE library_section_id = 30;
UPDATE metadata_item_views SET library_section_id = 3 WHERE library_section_id = 30;
UPDATE metadata_items SET library_section_id = 3 WHERE library_section_id = 30;
UPDATE section_locations SET library_section_id = 3 WHERE library_section_id = 30;
UPDATE synced_library_sections SET library_section_id = 3 WHERE library_section_id = 30;
UPDATE synced_metadata_items SET library_section_id = 3 WHERE library_section_id = 30;
UPDATE library_sections SET id = 3 WHERE id = 30;

Copied that edited database back and started Plex server… and now that specific library gives me a 404 error. Copied back the original database and it works again. Last in line, of course.

Did I miss a table/column somewhere?

1 Like

Why not restoring a former database backup?

An regarding sorting libraries:
‘edit’ your libraries and put one or several space characters in front of their names.
The library with the most space characters will be displayed first.
Most Plex clients do filter those leading spaces out, so nobody will spot what dirty trick you used here :wink:

Unfortunately my oldes backup is from 4 days after I messed up. And those spaces are a dirty trick, I’d rather do it right, to be honest.

Then your best choice is to stop Plex,

cd /var/lib/plexmediaserver
sudo rm -rf Library

Start Plex and go again.

That would mean losing all my watched states… that’s really not an option if I can help it. Guess I’ll have to live with it like this.

I was trying to do the same thing, and this worked for me!
Thanks so much!