PostgreSQL: Production fixes—UPSERT, remote backup, auth logs
- 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
This commit is contained in:
+31
-8
@@ -146,17 +146,40 @@ public sealed class PostgresDatabaseProvider : IJellyfinDatabaseProvider
|
||||
connectionBuilder.MaxPoolSize,
|
||||
connectionBuilder.Multiplexing);
|
||||
|
||||
// Initialize backup service if host is local and configuration manager is available
|
||||
if (IsLocalHost(currentHost) && configurationManager is not null)
|
||||
// Initialize backup service if configuration manager is available
|
||||
// Backup works for both local and remote servers via pg_dump/pg_restore client tools
|
||||
if (configurationManager is not null)
|
||||
{
|
||||
var loggerFactory = Microsoft.Extensions.Logging.Abstractions.NullLoggerFactory.Instance;
|
||||
var backupLogger = loggerFactory.CreateLogger<PostgresBackupService>();
|
||||
backupService = new PostgresBackupService(backupLogger, configurationManager);
|
||||
logger.LogInformation("PostgreSQL backup service initialized for local database (will use external pg_dump/pg_restore tools)");
|
||||
// Check if backups are explicitly disabled
|
||||
var disableBackups = GetOption(customOptions, "disable-backups", e => e.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase), () => false);
|
||||
|
||||
if (disableBackups)
|
||||
{
|
||||
logger.LogInformation("PostgreSQL backup service is disabled (disable-backups=true in configuration)");
|
||||
backupService = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var loggerFactory = Microsoft.Extensions.Logging.Abstractions.NullLoggerFactory.Instance;
|
||||
var backupLogger = loggerFactory.CreateLogger<PostgresBackupService>();
|
||||
backupService = new PostgresBackupService(backupLogger, configurationManager);
|
||||
|
||||
if (IsLocalHost(currentHost))
|
||||
{
|
||||
logger.LogInformation("PostgreSQL backup service initialized for local database at {Host} (using pg_dump/pg_restore tools)", currentHost);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogInformation("PostgreSQL backup service initialized for remote database at {Host} (using pg_dump/pg_restore tools)", currentHost);
|
||||
logger.LogWarning("Note: Ensure pg_dump and pg_restore client tools are installed locally and network connectivity to {Host} is available", currentHost);
|
||||
}
|
||||
|
||||
logger.LogInformation("PostgreSQL client binaries (pg_dump/pg_restore) must be in system PATH or specify full paths in BackupOptions");
|
||||
}
|
||||
}
|
||||
else if (!IsLocalHost(currentHost))
|
||||
else
|
||||
{
|
||||
logger.LogInformation("PostgreSQL database is on remote server ({Host}). Backup operations via external pg_dump/pg_restore tools are disabled", currentHost);
|
||||
logger.LogWarning("Configuration manager not available - PostgreSQL backup service disabled");
|
||||
}
|
||||
|
||||
options
|
||||
|
||||
Reference in New Issue
Block a user