Skip to main content

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

Connection String Parameters:
  • Server - Hostname or IP address
  • Database - Database name (default: vault)
  • User Id - Database user
  • Password - Database password
  • TrustServerCertificate=True - Accept self-signed certificates (dev only)
  • Encrypt=True - Enable encryption (recommended)
  • MultipleActiveResultSets=True - Enable MARS (optional)

PostgreSQL

Connection String Parameters:
  • Host - Hostname or IP address
  • Port - Port number (default: 5432)
  • Database - Database name
  • Username - Database user
  • Password - Database password
  • SSL Mode - Disable, Prefer, or Require

MySQL

Connection String Parameters:
  • Server - Hostname or IP address
  • Port - Port number (default: 3306)
  • Database - Database name
  • Uid - Database user
  • Pwd - Database password
  • SslMode - None, Preferred, or Required
Password Requirements: SQL Server requires passwords with:
  • At least 8 characters
  • At least one uppercase letter
  • At least one lowercase letter
  • At least one number
  • At least one special character

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
Production Warning: Automatic migrations on startup can cause race conditions when multiple instances start simultaneously. Use the migrator utility instead.

Database Schema

The Bitwarden database contains these primary tables:
  • User - User accounts and profiles
  • Device - Registered devices per user
  • AuthRequest - Passwordless authentication requests
  • SsoUser - SSO user mappings
  • U2f - FIDO2/WebAuthn credentials
  • Cipher - Vault items (logins, cards, notes, etc.)
  • Folder - User folders
  • Collection - Organization collections
  • CollectionCipher - Collection-cipher relationships
  • Send - Temporary secret sharing
  • Organization - Organization accounts
  • OrganizationUser - User-organization memberships
  • Group - Organization groups
  • GroupUser - Group memberships
  • Policy - Organization policies
  • Event - Audit log events
  • EventSystemUser - System-generated events
  • SsoConfig - SSO configuration
  • OrganizationApiKey - API keys
  • Installation - Installation identifiers
  • Grant - OAuth 2.0 grants (IdentityServer)
  • Transaction - Payment transactions

Performance Optimization

Indexes

Bitwarden migrations create optimal indexes automatically. Key indexes:
  • Cipher.UserId - User vault queries
  • Cipher.OrganizationId - Organization vault queries
  • Event.Date - Event log queries
  • CollectionCipher.CipherId and CollectionCipher.CollectionId - Collection relationships

SQL Server Recommendations

PostgreSQL Recommendations

Connection Pooling

Enable connection pooling for better performance: SQL Server:
PostgreSQL:

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
Read operations (vault sync, searches) will use the replica automatically.

Troubleshooting

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
Symptoms: Password validation failedSolutions:
  • Use a strong password with uppercase, lowercase, numbers, and symbols
  • Minimum 8 characters
  • Example: MyStr0ng!Pass
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
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

1

Use Strong Passwords

Generate random passwords with at least 20 characters for database users.
2

Restrict Network Access

Only allow connections from application servers. Use firewall rules or security groups.
3

Enable Encryption

Use TLS/SSL for database connections in production.
4

Regular Backups

Automate daily backups and test restore procedures regularly.
5

Monitor Access

Enable audit logging for database access and review logs regularly.
6

Principle of Least Privilege

Grant minimal required permissions to application database users.

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