SQLite (Default)
SQLite is the default database backend and is suitable for most use cases. It requires no external services and stores all data in a single file.Configuration
~ expands to your home directory. For Docker deployments:
SQLite Features
Automatic Backups
Automatic Backups
Codex-LB automatically creates backups before running database migrations.Backups are stored in the same directory as the database file with a timestamp:
WAL Mode
WAL Mode
Codex-LB enables SQLite’s Write-Ahead Logging (WAL) mode for improved concurrency and crash recovery.Benefits:These files are managed automatically and should be included in backups.
- Multiple readers can access the database while a writer is active
- Better crash recovery
- Improved performance for concurrent workloads
Connection Pooling
Connection Pooling
SQLite uses a connection pool for better performance:
- Pool Size: Maximum number of persistent connections
- Max Overflow: Additional connections that can be created temporarily
- Timeout: How long to wait for an available connection
SQLite Limitations
PostgreSQL
PostgreSQL is recommended for high-traffic deployments or when running multiple Codex-LB instances.Setup
- Install PostgreSQL (if not already installed):
- Create a Database and User:
- Configure Codex-LB:
Connection URL Format
PostgreSQL Connection Pool
PostgreSQL uses a connection pool for optimal performance:PostgreSQL vs SQLite
| Feature | SQLite | PostgreSQL |
|---|---|---|
| Setup | Zero config | Requires server |
| Concurrency | Limited | Excellent |
| Network Access | No | Yes |
| Multi-Instance | No | Yes |
| Backups | Automatic | Manual or tools |
| Performance | Fast for single instance | Better for high traffic |
Database Migrations
Codex-LB uses Alembic for database migrations. Migrations run automatically on startup by default.Automatic Migrations
- MIGRATE_ON_STARTUP: Run migrations automatically when Codex-LB starts
- FAIL_FAST: Stop startup if migrations fail (recommended for production)
Manual Migrations
If you prefer to run migrations manually:Backup & Recovery
SQLite Backups
SQLite backups are created automatically before migrations. To create manual backups:PostgreSQL Backups
Usepg_dump for PostgreSQL backups:
- pg_basebackup: Physical backups
- WAL archiving: Point-in-time recovery
- Cloud backups: AWS RDS automated backups, etc.
Troubleshooting
SQLite Database Locked
PostgreSQL Connection Refused
- Verify PostgreSQL is running:
sudo systemctl status postgresql - Check the connection URL format
- Verify firewall rules allow port 5432
- Check
pg_hba.conffor access permissions
Migration Failures
If migrations fail:- Check logs for specific error messages
- Verify database connectivity
- For SQLite, restore from automatic backup:
- For PostgreSQL, restore from
pg_dumpbackup