Skip to content

Shim crash (segfault / "Invalid uuid length") after successful migration + multiple migration issues #10

@abcattell91

Description

@abcattell91

Environment

Platform: Unraid 6.12.54
Docker image: ghcr.io/cgnl/plex-postgresql-linuxserver:latest (v1.2.0)
Plex version: 1.43.0.10492-121068a07 (baked into image)
PostgreSQL: postgres:15-alpine (separate container)
Library size: 108,556 metadata items, 71,550 blobs
Connection: TCP via host IP (Plex on Host networking, PostgreSQL on bridge with port 5432 mapped)

Summary
Migration completed successfully (all 33 tables, 108,556 items, 71,550 blobs) but Plex crashes immediately on startup with a segfault / Invalid uuid length exception. The shim initialises fully but Plex dies before the shim can write anything to its log file.

Issue 1 — Shim crash after successful migration (BLOCKER)
After full migration, Plex crash-loops on every startup:
[SHIM_INIT] Constructor complete (Linux, PID 769)
libc++abi: terminating with uncaught exception of type std::domain_error: Invalid uuid length
****** PLEX MEDIA SERVER CRASHED

Shim loads and completes constructor
Plex crashes before the shim writes anything to plex_redirect_pg.log (file is 0 bytes)
All data verified present in PostgreSQL (108,556 metadata_items, all library_sections with valid UUIDs, Preferences.xml has valid MachineIdentifier)
Running under gdb shows a segfault with no debug symbols:

Fatal signal: Segmentation fault
----- Backtrace -----
0x4d3574 ???
0x5cb4f9 ???
0x5cb68a ???
...

Crash occurs on Plex 1.43.0 (the version baked into the image) — not caused by auto-update
Crash also occurs on 1.43.1 (when VERSION=docker triggers auto-update)

Note: The crash may be related to our varchar(255) workaround (see Issue 2) — we had to ALTER columns to text and drop/recreate fts4_metadata_titles and fts4_metadata_titles_icu views. The views were recreated as:
sqlCREATE VIEW plex.fts4_metadata_titles AS SELECT id AS rowid, title, title_fts FROM plex.metadata_items;
CREATE VIEW plex.fts4_metadata_titles_icu AS SELECT id AS rowid, title, title_fts FROM plex.metadata_items;
These may not match the original view definitions exactly, which could contribute to the crash.

Issue 2 — varchar(255) columns cause silent migration failure on metadata_items
The PostgreSQL schema defines several columns on metadata_items as character varying(255):

guid
title
title_sort
original_title
studio
content_rating

SQLite has no length limits, so real-world Plex databases can have values exceeding 255 characters. In my case:

guid column: A file-based GUID exceeded 255 chars:

file:///data/media/movies/Borat%20Cultural%20Learnings%20of%20America%20for%20Make%20Benefit%20Glori...

title column: An anime episode title exceeded 255 chars:

Let Your Eyes Behold the Glory and Mystery of the Brothel with a Perfect Score! Take a Newlywed or a...
PostgreSQL rejects the entire COPY operation, causing all 108,556 rows to fail. Migration reports FAIL but continues with other tables.
Suggested fix: Change all varchar(255) columns on metadata_items (and potentially other tables) to text in plex_schema.sql. SQLite uses text for everything, so there's no reason to impose length limits.

Issue 3 — Migration errors piped to /dev/null
In migrate_lib.sh, the migration call suppresses stderr:
bashif python3 "$migrate_py" ... 2>/dev/null; then
When metadata_items failed, the only output was FAIL — no indication of why. The actual PostgreSQL error (value too long for type character varying(255)) was only visible in the PostgreSQL container logs, which took significant debugging to discover.
Suggested fix: Log stderr to a migration log file instead of discarding it:
bashif python3 "$migrate_py" ... 2>>"$LOG_DIR/migration_errors.log"; then

Issue 4 — pg_trgm extension not created before schema load
The schema SQL references gin_trgm_ops for an index, but the pg_trgm extension isn't created before loading the schema. This causes an error on first run:
psql:/usr/local/lib/plex-postgresql/plex_schema.sql:4040: ERROR: operator class "plex.gin_trgm_ops" does not exist for access method "gin"
Suggested fix: Add CREATE EXTENSION IF NOT EXISTS pg_trgm; to the entrypoint before loading plex_schema.sql.

Issue 5 — Entrypoint drops and recreates schema on every restart when it considers DB "empty"
When metadata_items fails to migrate, the summary reports Total items in PostgreSQL: 0 even though 32 other tables migrated successfully. On the next container start, the entrypoint sees "0 items", considers the database empty, drops the schema, and re-runs the full migration — wiping out any manual fixes (like ALTERing column types).
This creates a frustrating loop where:

Migration fails on metadata_items
User manually fixes the schema (e.g. ALTER varchar to text)
Container restarts, drops schema, recreates with varchar(255), migration fails again

Suggested fix: Don't use metadata_items count as the sole indicator of whether data exists. Check multiple tables, or add a migration state flag.

Issue 6 — VERSION=docker triggers Plex auto-update inside container
The linuxserver base image auto-updates Plex when VERSION=docker. On first start, Plex upgraded from 1.43.0 (baked into the image) to 1.43.1. If the shim is compiled against a specific Plex version, this could cause compatibility issues.
Suggested fix: Document that VERSION should be left unset or pinned to the version the image was built with. Alternatively, the entrypoint could block auto-updates.

Issue 7 — doctor.sh not included in Docker image
The README references doctor.sh for database health checks, but it's not copied into the Docker image. The Dockerfile only copies migrate_lib.sh, migrate_table.py, docker-entrypoint.sh, and schema SQL files.

Suggested fix: Add COPY scripts/doctor.sh /usr/local/lib/plex-postgresql/ to the Dockerfile.
Steps to Reproduce

Set up postgres:15-alpine container
Run ghcr.io/cgnl/plex-postgresql-linuxserver:latest with TCP connection to PostgreSQL
Mount an existing Plex SQLite database (~108K items) at /source-db
Migration will fail on metadata_items if any guid or title values exceed 255 characters
Even after manually fixing the varchar issue and achieving full migration, Plex crashes on startup with Invalid uuid length

Workaround Applied
To get metadata_items to migrate, I had to:

Wait for migration to complete (with metadata_items FAIL)
Drop views fts4_metadata_titles and fts4_metadata_titles_icu
ALTER all varchar(255) columns on metadata_items to text
Recreate the views
Restart the container (entrypoint re-ran migration, this time successfully)

The migration then completed fully, but Plex still crashes on startup.
Current State

PostgreSQL database is fully migrated and verified clean (108,556 items, 0 self-referential rows, 0 orphan seasons)
Plex is rolled back to standard lscr.io/linuxserver/plex:latest and running on SQLite
PostgreSQL container and data preserved, ready to retry when the shim crash is fixed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions