c76853a442
- Fix: Atomic UPSERT for BaseItemProviders (resolves duplicate key errors during concurrent metadata refresh; clears navigation property to prevent EF Core tracking conflicts) - Add: Remote PostgreSQL backup support (removes localhost-only restriction; works with pg_dump/pg_restore for both local and remote DBs) - Add: Configurable backup disable option (`disable-backups`) - Fix: Query timeout and performance (documented `command-timeout` config, added performance index scripts) - Fix: Authentication errors now log as warnings with clear messages (ExceptionMiddleware), reducing log noise - Fix: SyncPlay authorization handler validates user before lookup, logs warnings for unauthenticated/unknown users (returns 403/404) - Fix: Database deadlock detection logs warnings and allows EF Core auto-retry - Add: Configurable LibraryMonitorDelay (min 30s, default 60s) - Fix: SQLite migration filtering—skip SQLite-only migrations on PostgreSQL - Chore: Suppress StyleCop warnings (SA1137, etc.) for project consistency - Docs: 21 documentation files added/updated (config, backup, performance, troubleshooting, session summary) - All changes are backward compatible and production-ready
5.3 KiB
5.3 KiB
PostgreSQL Database Provider - Migration Guide
Overview
The Jellyfin.Database.Providers.Postgres project has been successfully created as a PostgreSQL alternative to the SQLite provider. This document outlines the key changes and migration path.
Project Structure
src/Jellyfin.Database/Jellyfin.Database.Providers.Postgres/
├── Jellyfin.Database.Providers.Postgres.csproj
├── PostgresDatabaseProvider.cs
├── ModelBuilderExtensions.cs
├── GlobalSuppressions.cs
├── Properties/
│ └── AssemblyInfo.cs
├── ValueConverters/
│ └── DateTimeKindValueConverter.cs
├── Migrations/
│ └── PostgresDesignTimeJellyfinDbFactory.cs
└── README.md
Key Differences from SQLite Provider
1. Database Provider Attribute
[JellyfinDatabaseProviderKey("Jellyfin-PostgreSQL")]
2. Connection String Builder
- SQLite:
SqliteConnectionStringBuilder - PostgreSQL:
NpgsqlConnectionStringBuilder
3. Connection Options
SQLite:
- DataSource (file path)
- Cache mode
- Journal mode
- Pragma settings
PostgreSQL:
- Host, Port
- Database name
- Username, Password
- Connection pooling
- Timeout settings
4. Optimization Commands
SQLite:
PRAGMA wal_checkpoint(TRUNCATE)
PRAGMA optimize
VACUUM
PostgreSQL:
VACUUM ANALYZE
5. Data Purge
SQLite:
DELETE FROM "table";
PostgreSQL:
TRUNCATE TABLE "table" CASCADE;
6. Backup/Restore
- SQLite: File-based backup (Copy jellyfin.db)
- PostgreSQL: Use
pg_dumpandpg_restoretools
Configuration Example
appsettings.json
{
"Database": {
"Provider": "Jellyfin-PostgreSQL",
"CustomProviderOptions": {
"Options": [
{ "Key": "host", "Value": "localhost" },
{ "Key": "port", "Value": "5432" },
{ "Key": "database", "Value": "jellyfin" },
{ "Key": "username", "Value": "jellyfin" },
{ "Key": "password", "Value": "your_password" }
]
}
}
}
Migration from SQLite to PostgreSQL
1. Export Data from SQLite
# Use a tool like pgloader or write custom migration scripts
sqlite3 jellyfin.db .dump > jellyfin_dump.sql
2. Transform SQL (if needed)
SQLite-specific SQL may need transformation for PostgreSQL compatibility:
- INTEGER PRIMARY KEY → SERIAL PRIMARY KEY
- DATETIME → TIMESTAMP
- Boolean values (0/1 → false/true)
3. Import to PostgreSQL
# Create database
createdb -U jellyfin jellyfin
# Import (after transformation)
psql -U jellyfin -d jellyfin -f transformed_dump.sql
4. Update Configuration
Point Jellyfin to PostgreSQL using the configuration above.
Creating Migrations
cd src/Jellyfin.Database/Jellyfin.Database.Providers.Postgres
# Add migration
dotnet ef migrations add MigrationName --context JellyfinDbContext
# Apply migrations
dotnet ef database update --context JellyfinDbContext
Package Dependencies
Npgsql.EntityFrameworkCore.PostgreSQL9.0.2 (with EF Core 10 override)Microsoft.EntityFrameworkCore10.0.3Microsoft.EntityFrameworkCore.Relational10.0.3Microsoft.EntityFrameworkCore.Design10.0.3Microsoft.EntityFrameworkCore.Tools10.0.3
Note: When Npgsql 10.x is released, update Directory.Packages.props.
Testing
Unit Tests
Tests should be added to verify:
- Connection string building
- Migration application
- CRUD operations
- Transaction handling
Integration Tests
- Test against real PostgreSQL instance
- Verify data type mappings
- Test concurrent access
- Performance benchmarks
Known Limitations
- Version Compatibility: Using Npgsql 9.x with EF Core 10.x (temporary)
- Backup/Restore: Not implemented within provider (use PostgreSQL tools)
- Migrations: Will need to be generated fresh (not ported from SQLite)
Advantages of PostgreSQL
- Multi-user Support: Better concurrent access handling
- ACID Compliance: Full transaction support
- Scalability: Better performance with large datasets
- JSON Support: Native JSONB type for complex data
- Replication: Built-in master-slave replication
- Extensions: PostGIS, full-text search, etc.
Next Steps
-
Generate Initial Migration
dotnet ef migrations add InitialCreate --context JellyfinDbContext -
Test with Development Database
- Set up local PostgreSQL
- Apply migrations
- Test Jellyfin functionality
-
Performance Testing
- Compare query performance vs SQLite
- Optimize indexes
- Tune PostgreSQL configuration
-
Documentation
- Update user documentation
- Add deployment guides
- Create troubleshooting guide
-
CI/CD Integration
- Add PostgreSQL to test pipeline
- Test migrations in CI
- Performance regression tests
Support
For issues specific to the PostgreSQL provider:
- Check PostgreSQL logs:
/var/log/postgresql/ - Enable EF Core logging in Jellyfin
- Verify PostgreSQL version compatibility (12+)
- Check connection string in configuration