Refactor PostgreSQL provider: multi-schema & async prep

- Refactor migrations and provider to use multiple PostgreSQL schemas, each matching a legacy SQLite database (activitylog, authentication, displaypreferences, library, users).
- All tables, foreign keys, and indexes are now schema-qualified; Down migration drops tables by schema.
- Provider ensures schemas exist before migrations; entities are mapped to correct schemas in OnModelCreating.
- Add support for max-pool-size, min-pool-size, and multiplexing connection options; update logging accordingly.
- VACUUM ANALYZE now runs per schema during scheduled optimization.
- TruncateAllTablesAsync now truncates tables with schema qualification.
- README updated with schema structure, new options, and multiplexing warnings.
- CacheDecorator now calls async repository methods using .GetAwaiter().GetResult(), with documentation.
- Lays groundwork for full async/await and multiplexing support in the database layer.
This commit is contained in:
2026-02-23 09:38:22 -05:00
parent ede6904433
commit 86883cd5c6
51 changed files with 6719 additions and 187 deletions
@@ -26,6 +26,8 @@ To use PostgreSQL as the database backend, configure the following options in yo
{ "Key": "username", "Value": "jellyfin" },
{ "Key": "password", "Value": "your_secure_password" },
{ "Key": "pooling", "Value": "true" },
{ "Key": "max-pool-size", "Value": "100" },
{ "Key": "min-pool-size", "Value": "0" },
{ "Key": "command-timeout", "Value": "30" },
{ "Key": "connection-timeout", "Value": "15" }
]
@@ -83,19 +85,46 @@ psql -U jellyfin -h localhost jellyfin < jellyfin_backup.sql
| username | jellyfin | Database username |
| password | (empty) | Database password |
| pooling | true | Enable connection pooling |
| max-pool-size | 100 | Maximum number of connections in the pool |
| min-pool-size | 0 | Minimum number of connections in the pool |
| command-timeout | 30 | Command timeout in seconds |
| connection-timeout | 15 | Connection timeout in seconds |
| multiplexing | false | ⚠️ **Advanced**: Enable command multiplexing (requires all async operations) |
| EnableSensitiveDataLogging | false | Enable sensitive data logging (for debugging) |
### ⚠️ Multiplexing Warning
**Multiplexing is disabled by default** because it requires all database operations to be asynchronous. Enabling multiplexing will cause errors like:
```
System.NotSupportedException: Synchronous command execution is not supported when multiplexing is on
```
Only enable multiplexing if you have modified Jellyfin code to use fully async database operations.
## Performance Tuning
For better performance, consider:
1. **Indexes**: The provider will create necessary indexes through migrations
2. **Connection Pooling**: Enabled by default
2. **Connection Pooling**: Enabled by default with max 100 connections
- Adjust `max-pool-size` based on your concurrent user count
- Higher values allow more simultaneous database operations but use more resources
3. **Vacuum**: Scheduled optimization runs `VACUUM ANALYZE` periodically
4. **PostgreSQL Configuration**: Adjust `shared_buffers`, `effective_cache_size`, etc. in postgresql.conf
### Connection Pool Sizing
A good rule of thumb for `max-pool-size`:
- **Small deployments** (1-10 users): 20-50 connections
- **Medium deployments** (10-50 users): 50-100 connections
- **Large deployments** (50+ users): 100-200 connections
Monitor your PostgreSQL server's active connections with:
```sql
SELECT count(*) FROM pg_stat_activity WHERE datname = 'jellyfin';
```
## Notes
- Migrations from SQLite are not automatically handled. You'll need to export data from SQLite and import into PostgreSQL manually.