Files
pgsql-jellyfin/docs/REMOTE_ANALYSIS_SUMMARY.md
T
wjones 78c8d4256c Docs reorg, config refactor, and ItemValues index fix
- Moved all documentation to docs/ and updated README with categorized links and new docs/INDEX.md
- Added HOW_TO_SWITCH_DATABASE.md and several new analysis/action docs
- Introduced db-config.ps1 for centralized DB config; all scripts now use it for easy DB switching
- Added db-quick.ps1 for interactive diagnostics and index management
- Updated Add-All-Indexes.bat to use db-config.ps1
- Added Fix-ItemValues-Performance.ps1 to create 3 critical indexes on ItemValues, addressing 1.3B row seq scan issue
- Updated performance_indexes.sql with new ItemValues indexes and ANALYZE
- Updated diagnostics.sql and database_report.txt for improved output and clarity
- All scripts and docs now reference the new config and index optimization workflow
2026-02-28 16:23:43 -05:00

5.4 KiB
Raw Blame History

Remote Database Analysis - Quick Summary

Your Configuration

Database Connection:

Host: 192.168.129.248 (Remote PostgreSQL Server)
Port: 5432
User: postgres (Superuser)
Database: jellyfin_testdata  (Already corrected in your config!)

Your db-config.ps1 is correct! 🎉


📊 Diagnostics Analysis Summary

What's Working:

  1. No critical errors - Database is healthy
  2. High index usage on most tables (94-99%)
  3. Low bloat (2.5-5.5% dead tuples)
  4. No blocking/locks - Database running smoothly

🔴 Critical Issue: ItemValues Table

The Problem:

Sequential Scans: 226,121
Rows Read: 1,313,356,213 (1.3 BILLION!)
Index Usage: Only 52%
Average per scan: 5,808 rows

Why It's Critical:

  • This table handles genres, tags, studios, etc.
  • 1.3 billion rows being scanned instead of using indexes
  • On a remote database, network amplifies the slowdown
  • Every genre filter = massive data transfer

Impact:

  • Filtering by genre: SLOW 🐌
  • Searching tags: SLOW 🐌
  • Metadata queries: SLOW 🐌

⚠️ Secondary Issue: Peoples Table

Sequential Scans: 19,320
Rows Read: 918,704,169 (918 MILLION!)

Impact: Actor/director searches are slow

Supplementary Indexes: Untested

Your new indexes show minimal usage:

  • idx_baseitems_datecreated_filtered: 0 uses
  • idx_itemvaluesmap_itemvalueid_itemid: 10 uses

Why? Database was idle when you ran diagnostics.


🚀 What You Need To Do

Step 1: Update Statistics (Now)

. .\db-config.ps1
Invoke-PSQL -Query "ANALYZE VERBOSE library.ItemValues, library.Peoples, library.BaseItems;"

This tells PostgreSQL about the actual data distribution.

Step 2: Use Jellyfin (This Week)

Connect Jellyfin to this remote database and perform these actions:

Test Supplementary Indexes:

  • Browse "Recently Added" → Tests date filtering index
  • Filter by Genre → Tests value mapping index
  • Browse library folders → Tests folder hierarchy index
  • Search for actors → Tests people queries

Generate Workload:

  • Use Jellyfin normally for 1 week
  • Let it accumulate query statistics
  • This shows which indexes actually help

Step 3: Re-run Diagnostics (Next Week)

. .\db-config.ps1
Invoke-PSQL -File "sql\diagnostics.sql" -OutputFile "diagnostics_week2.txt"

Compare:

  • Are supplementary indexes being used?
  • Has ItemValues improved?
  • Any new bottlenecks?

Step 4: Optimize Based on Real Data

After seeing actual usage:

  • Keep indexes that show >100 uses
  • Remove indexes with 0-10 uses (after 30 days)
  • Create targeted indexes for ItemValues
  • Document improvements

🌐 Why Remote Matters

Local database:

  • Query time = Processing time
  • 1 second query = 1 second wait

Remote database (192.168.129.248):

  • Query time = Processing + Network
  • 1 second query + 5ms network × 1000 rows = 6 seconds!

With 1.3 billion rows scanned:

  • Network transfers become massive
  • Indexes are EVEN MORE critical
  • Sequential scans = disaster

Example:

Without index (current):
- Scan 1.3B rows: 5000ms processing
- Transfer 10K results: 50ms network
- Total: 5050ms (5+ seconds) ❌

With proper index:
- Use index: 50ms processing
- Transfer 100 results: 1ms network
- Total: 51ms (instant) ✅

🎯 Priority Actions

🔴 Critical (Do Now):

  1. Config file correct (already done!)
  2. Update statistics (command above)
  3. Use Jellyfin for 1 week

🟡 High (This Week):

  1. Test genre/tag filtering
  2. Test recently added browsing
  3. Monitor any slow operations

🟢 Medium (Next Week):

  1. Run diagnostics again
  2. Compare index usage
  3. Create ItemValues optimized indexes

Low (After 30 Days):

  1. Remove unused indexes
  2. Document final optimization results

📈 Expected Improvements

After proper optimization:

Operation Current Expected Improvement
Genre filter 5+ seconds <500ms 90% faster
Recently Added 2-3 seconds <200ms 93% faster
Actor search 1-2 seconds <100ms 95% faster
Library browse 1 second <50ms 95% faster

Overall: 70-90% performance improvement expected! 🚀


📋 Quick Command Reference

Check Connection:

. .\db-config.ps1
Invoke-PSQL -Query "SELECT current_database(), current_user, inet_server_addr();"

Update Statistics:

. .\db-config.ps1
Invoke-PSQL -Query "ANALYZE;"

Run Diagnostics:

. .\db-config.ps1
Invoke-PSQL -File "sql\diagnostics.sql" -OutputFile "diagnostics_$(Get-Date -Format 'yyyy-MM-dd').txt"

Check Index Usage:

. .\db-config.ps1
Invoke-PSQL -Query "SELECT indexname, idx_scan FROM pg_stat_user_indexes WHERE schemaname = 'library' AND indexname LIKE 'idx_%' ORDER BY idx_scan DESC;"

🎓 Bottom Line

Your database is healthy, but has one major bottleneck:

Connection working (remote server @ 192.168.129.248)
Config correct (jellyfin_testdata)
⚠️ ItemValues table needs optimization (1.3B rows scanned!)
📊 Supplementary indexes need testing (currently unused)

Action: Use Jellyfin for 1 week, then re-analyze. The remote setup is fine - it's the indexes that need work!

See REMOTE_DATABASE_ANALYSIS.md for complete technical details. 📖