Postgres perf, path migration, and shutdown race fixes

- Major query performance boost: replaced correlated subqueries with DistinctBy() in BaseItemRepository, added episode deduplication index, and increased default command timeout to 120s.
- Fixed LibraryMonitor shutdown race: added disposal checks and exception handling in FileRefresher to prevent ObjectDisposedException.
- Added PowerShell and SQL utilities for fixing Linux paths in config files and database; new scripts for WebDir and path migration.
- Auto-fix for WebDir in startup.json on load; new helper scripts and docs.
- Added automated weekly DB performance monitoring scripts and reporting.
- Expanded documentation and README for all fixes, scripts, and migration steps.
- Updated SQL scripts for index creation and diagnostics; improved output handling.
- Updated db-config defaults and added new diagnostic/report files.
This commit is contained in:
2026-03-05 08:56:42 -05:00
parent 0eb44818ff
commit 7eb2b445cb
44 changed files with 3504 additions and 23 deletions
+146
View File
@@ -0,0 +1,146 @@
-- PostgreSQL Path Fix for Windows
-- This script converts Linux paths stored in the database to Windows paths
-- Run this if you migrated from Linux or have incorrect paths in your database
\pset pager off
-- IMPORTANT: Backup your database before running this script!
-- Step 1: Check what paths exist in your database
SELECT 'ImageInfo Paths' AS table_name, COUNT(*) AS count,
COUNT(CASE WHEN "Path" LIKE '/var/lib/jellyfin/%' THEN 1 END) AS linux_paths,
COUNT(CASE WHEN "Path" LIKE '/var/%' OR "Path" LIKE '/usr/%' THEN 1 END) AS all_linux_paths
FROM library."ImageInfos"
UNION ALL
SELECT 'BaseItems Paths' AS table_name, COUNT(*) AS count,
COUNT(CASE WHEN "Path" LIKE '/var/lib/jellyfin/%' THEN 1 END) AS linux_paths,
COUNT(CASE WHEN "Path" LIKE '/var/%' OR "Path" LIKE '/usr/%' THEN 1 END) AS all_linux_paths
FROM library."BaseItems";
-- Step 2: Show sample paths that will be updated
(SELECT '"ImageInfos"' AS table_name, "Id"::text, "Path" AS current_path
FROM library."ImageInfos"
WHERE "Path" LIKE '/var/lib/jellyfin/%' OR "Path" LIKE '/var/%' OR "Path" LIKE '/usr/%'
LIMIT 10)
UNION ALL
(SELECT '"BaseItems"' AS table_name, "Id"::text, "Path" AS current_path
FROM library."BaseItems"
WHERE "Path" LIKE '/var/lib/jellyfin/%' OR "Path" LIKE '/var/%' OR "Path" LIKE '/usr/%'
LIMIT 10);
-- Step 3: Preview the path conversion (does NOT modify data)
-- This shows you what the new paths will look like
SELECT
"Id",
"Path" AS old_path,
REGEXP_REPLACE(
REGEXP_REPLACE(
"Path",
'^/var/lib/jellyfin',
'C:/ProgramData/jellyfin/data',
'g'
),
'/',
'\',
'g'
) AS new_path
FROM library."ImageInfos"
WHERE "Path" LIKE '/var/lib/jellyfin/%'
LIMIT 5;
-- ===========================================================================
-- STOP HERE AND REVIEW THE OUTPUT ABOVE BEFORE PROCEEDING!
-- ===========================================================================
-- If the preview looks correct, uncomment and run the UPDATE statements below
/*
-- Step 4: Update ImageInfo paths
-- Convert: /var/lib/jellyfin -> C:/ProgramData/jellyfin/data
-- Convert: / -> \
BEGIN;
UPDATE library."ImageInfos"
SET "Path" = REGEXP_REPLACE(
REGEXP_REPLACE(
"Path",
'^/var/lib/jellyfin',
'C:/ProgramData/jellyfin/data',
'g'
),
'/',
'\',
'g'
)
WHERE "Path" LIKE '/var/lib/jellyfin/%';
-- Show how many rows were updated
SELECT 'Updated ImageInfos: ' || ROW_COUNT() AS result;
COMMIT;
-- Step 5: Update BaseItems paths (if needed)
BEGIN;
UPDATE library."BaseItems"
SET "Path" = REGEXP_REPLACE(
REGEXP_REPLACE(
"Path",
'^/var/lib/jellyfin',
'C:/ProgramData/jellyfin/data',
'g'
),
'/',
'\',
'g'
)
WHERE "Path" LIKE '/var/lib/jellyfin/%';
SELECT 'Updated BaseItems: ' || ROW_COUNT() AS result;
COMMIT;
-- Step 6: Update any other Linux paths (e.g., /usr/share/jellyfin)
BEGIN;
UPDATE library."BaseItems"
SET "Path" = REGEXP_REPLACE(
REGEXP_REPLACE(
"Path",
'^/usr/share/jellyfin',
'C:/Program Files/Jellyfin',
'g'
),
'/',
'\',
'g'
)
WHERE "Path" LIKE '/usr/share/jellyfin/%';
SELECT 'Updated BaseItems (usr/share): ' || ROW_COUNT() AS result;
COMMIT;
-- Step 7: Verify the changes
SELECT 'Verification - ImageInfos' AS check_type,
COUNT(*) AS total_rows,
COUNT(CASE WHEN "Path" LIKE '/var/%' OR "Path" LIKE '/usr/%' THEN 1 END) AS remaining_linux_paths
FROM library."ImageInfos"
UNION ALL
SELECT 'Verification - BaseItems' AS check_type,
COUNT(*) AS total_rows,
COUNT(CASE WHEN "Path" LIKE '/var/%' OR "Path" LIKE '/usr/%' THEN 1 END) AS remaining_linux_paths
FROM library."BaseItems";
*/
-- ===========================================================================
-- IMPORTANT NOTES:
-- ===========================================================================
-- 1. This script assumes your Windows Jellyfin data is at C:/ProgramData/jellyfin/data
-- If it's different, update the path in the REGEXP_REPLACE statements
--
-- 2. The script converts forward slashes (/) to backslashes (\)
-- However, .NET's Path class accepts forward slashes on Windows too
--
-- 3. You may need to restart Jellyfin after running this script
--
-- 4. If you have custom metadata paths, you'll need to adjust the script accordingly