Overview
Bitwarden Server requires a SQL database to store user data, vault items, organizations, and system configuration. The database is shared across all services.Supported Databases
SQL Server
Recommended - SQL Server 2017+Microsoft’s enterprise database. Best performance and full feature support.
PostgreSQL
PostgreSQL 12+Open-source alternative with excellent performance.
MySQL / MariaDB
MySQL 8.0+ / MariaDB 10.5+Widely available open-source databases.
Production Recommendation: Use SQL Server 2022 or PostgreSQL 14+ for best performance and reliability.
Quick Start with Docker
SQL Server
PostgreSQL
MySQL
Connection Strings
SQL Server
Server- Hostname or IP addressDatabase- Database name (default:vault)User Id- Database userPassword- Database passwordTrustServerCertificate=True- Accept self-signed certificates (dev only)Encrypt=True- Enable encryption (recommended)MultipleActiveResultSets=True- Enable MARS (optional)
PostgreSQL
Host- Hostname or IP addressPort- Port number (default: 5432)Database- Database nameUsername- Database userPassword- Database passwordSSL Mode-Disable,Prefer, orRequire
MySQL
Server- Hostname or IP addressPort- Port number (default: 3306)Database- Database nameUid- Database userPwd- Database passwordSslMode-None,Preferred, orRequired
Database Migrations
Bitwarden uses database migrations to create and update the schema. Migrations must be run before starting services.Using Migrator Utility
The recommended way to run migrations:The
--network flag ensures the migrator can reach the database container. Adjust the network name based on your Docker Compose project.Manual Migrations
For non-Docker deployments, run the migrator utility directly:Hosted Service Migrations
Services can automatically run migrations on startup:appsettings.json
Database Schema
The Bitwarden database contains these primary tables:User & Authentication
User & Authentication
User- User accounts and profilesDevice- Registered devices per userAuthRequest- Passwordless authentication requestsSsoUser- SSO user mappingsU2f- FIDO2/WebAuthn credentials
Vault Data
Vault Data
Cipher- Vault items (logins, cards, notes, etc.)Folder- User foldersCollection- Organization collectionsCollectionCipher- Collection-cipher relationshipsSend- Temporary secret sharing
Organizations
Organizations
Organization- Organization accountsOrganizationUser- User-organization membershipsGroup- Organization groupsGroupUser- Group membershipsPolicy- Organization policies
Events & Audit
Events & Audit
Event- Audit log eventsEventSystemUser- System-generated eventsSsoConfig- SSO configurationOrganizationApiKey- API keys
System
System
Installation- Installation identifiersGrant- OAuth 2.0 grants (IdentityServer)Transaction- Payment transactions
Performance Optimization
Indexes
Bitwarden migrations create optimal indexes automatically. Key indexes:Cipher.UserId- User vault queriesCipher.OrganizationId- Organization vault queriesEvent.Date- Event log queriesCollectionCipher.CipherIdandCollectionCipher.CollectionId- Collection relationships
SQL Server Recommendations
PostgreSQL Recommendations
Connection Pooling
Enable connection pooling for better performance: SQL Server:Backup and Restore
SQL Server Backup
PostgreSQL Backup
MySQL Backup
Automation: Set up automated daily backups using cron jobs or container orchestration tools.
Read Replicas
For high-traffic deployments, configure read replicas:appsettings.json
Troubleshooting
Cannot connect to database
Cannot connect to database
Symptoms: Services fail to start with connection errorsSolutions:
- Verify database is running:
docker ps - Check connection string credentials
- Ensure database port is accessible
- Test connection:
telnet localhost 1433 - Check firewall rules
Password policy errors (SQL Server)
Password policy errors (SQL Server)
Symptoms:
Password validation failedSolutions:- Use a strong password with uppercase, lowercase, numbers, and symbols
- Minimum 8 characters
- Example:
MyStr0ng!Pass
Migrations fail
Migrations fail
Symptoms: Migration errors during startupSolutions:
- Run migrations manually using migrator utility
- Check database user has CREATE TABLE permissions
- Verify connection string is correct
- Review migration logs for specific errors
Performance issues
Performance issues
Symptoms: Slow queries, timeoutsSolutions:
- Check database resource usage (CPU, memory, disk)
- Review slow query logs
- Update statistics:
EXEC sp_updatestats - Consider adding read replicas
- Increase connection pool size
Security Best Practices
Restrict Network Access
Only allow connections from application servers. Use firewall rules or security groups.
Next Steps
Configuration
Configure connection strings in appsettings.json
Docker Deployment
Deploy services with Docker Compose
Backup & Restore
Set up automated backups
Monitoring
Monitor database performance