Skip to main content
Homarr supports three database systems: SQLite, MySQL, and PostgreSQL. This guide covers setup, migrations, and maintenance.

Supported Databases

SQLite is the default database and recommended for most users. It’s a file-based database that requires no additional setup.

Advantages

  • Zero configuration
  • No separate database server required
  • Perfect for single-instance deployments
  • Easy backups (just copy the file)

Configuration

.env
DB_DRIVER='better-sqlite3'
DB_URL='/path/to/your/database/db.sqlite'
DB_URL must be an absolute path, not a relative path.

Production Default

In production environments, if DB_URL is not set, Homarr defaults to:
/appdata/db/db.sqlite

Setup

  1. Set the environment variables in your .env file
  2. Start Homarr - the database file will be created automatically
  3. Migrations run automatically on first startup

Database Migrations

Homarr uses Drizzle ORM for database migrations. Migrations are automatically applied when Homarr starts.

Migration Files

Migrations are located in the packages/db/migrations/ directory:
packages/db/migrations/
├── sqlite/          # SQLite-specific migrations
├── mysql/           # MySQL-specific migrations
├── postgresql/      # PostgreSQL-specific migrations
└── custom/          # Custom data migrations

Automatic Migrations

Migrations run automatically in the following order:
  1. Schema migrations - Create/update tables and columns
  2. Seed data - Insert default data (groups, settings)
  3. Custom migrations - Data transformations and updates
You’ll see output like this on startup:
Migration complete

Manual Migration (Development)

For development, you can run migrations manually:
pnpm --filter @homarr/db migrate:sqlite

Custom Migrations

Homarr includes custom migrations for data transformations:
  • 0000_release_widget_provider_to_options.ts - Migrates widget provider data to options format
  • 0001_opnsense_credentials.ts - Updates OPNsense integration credentials
  • 0002_app_widget_show_description_tooltip_to_display_mode.ts - Migrates tooltip settings to display mode
These run automatically after schema migrations.

Connection Troubleshooting

SQLite Issues

Ensure the directory exists and Homarr has write permissions:
mkdir -p /path/to/database
chmod 755 /path/to/database
SQLite doesn’t support multiple concurrent writers. Ensure only one Homarr instance is using the database file.

MySQL Issues

Verify user permissions:
SHOW GRANTS FOR 'homarr'@'%';
Grant all privileges if needed:
GRANT ALL PRIVILEGES ON homarr.* TO 'homarr'@'%';
FLUSH PRIVILEGES;
Check if MySQL is running and accessible:
mysql -h localhost -u homarr -p
Verify DB_HOST and DB_PORT are correct.

PostgreSQL Issues

Check PostgreSQL is running:
psql -h localhost -U homarr -d homarr
Edit postgresql.conf to ensure PostgreSQL listens on the correct interface:
listen_addresses = '*'
Create the database:
CREATE DATABASE homarr;

Backup and Restore

SQLite Backup

SQLite databases are simple files - just copy them:
# Backup
cp /path/to/db.sqlite /path/to/backup/db.sqlite.backup

# Restore
cp /path/to/backup/db.sqlite.backup /path/to/db.sqlite
Stop Homarr before backing up to ensure data consistency.

MySQL Backup

# Backup
mysqldump -u homarr -p homarr > homarr_backup.sql

# Restore
mysql -u homarr -p homarr < homarr_backup.sql

PostgreSQL Backup

# Backup
pg_dump -U homarr -d homarr > homarr_backup.sql

# Restore
psql -U homarr -d homarr < homarr_backup.sql

Database Maintenance

SQLite Maintenance

Optimize database periodically:
sqlite3 /path/to/db.sqlite 'VACUUM;'

MySQL Maintenance

Optimize tables:
OPTIMIZE TABLE table_name;
Analyze tables for better query performance:
ANALYZE TABLE table_name;

PostgreSQL Maintenance

Vacuum and analyze:
VACUUM ANALYZE;
Reindex for better performance:
REINDEX DATABASE homarr;

Migrating Between Databases

To migrate from one database type to another:
  1. Export data from old database
  2. Set up new database with correct DB_DRIVER
  3. Start Homarr (migrations will run)
  4. Use database-specific tools to migrate data
There’s no automated migration tool between different database systems. Plan carefully and test in a staging environment.

Performance Tuning

SQLite

# In SQLite shell
PRAGMA journal_mode = WAL;  # Write-Ahead Logging
PRAGMA synchronous = NORMAL;
PRAGMA cache_size = 10000;

MySQL

Edit my.cnf:
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
max_connections = 200

PostgreSQL

Edit postgresql.conf:
shared_buffers = 256MB
effective_cache_size = 1GB
work_mem = 16MB
maintenance_work_mem = 128MB

Next Steps

Build docs developers (and LLMs) love