Supported Databases
Grafana supports three database backends:- SQLite - Default, embedded database (recommended for testing and small deployments)
- PostgreSQL - Recommended for production deployments
- MySQL/MariaDB - Supported for production deployments
SQLite Configuration
SQLite is the default database and requires no external database server.Configuration File
Environment Variables
Limitations
- Not recommended for production high-availability setups
- Limited concurrent write performance
- Not suitable for multiple Grafana instances
- Maximum database size depends on disk space
Use Cases
- Development and testing
- Single-server deployments
- Low-traffic installations
- Embedded or edge deployments
PostgreSQL Configuration
PostgreSQL is the recommended database for production deployments.Configuration File
Environment Variables
Connection URL Format
Alternatively, use a connection URL:SSL/TLS Configuration
Disable SSL (not recommended for production):PostgreSQL Setup
Create the Grafana database and user:MySQL/MariaDB Configuration
MySQL and MariaDB are supported for production deployments.Configuration File
Environment Variables
Connection URL Format
MySQL Setup
Create the Grafana database and user:Character Set Requirements
Grafana requiresutf8mb4 character set for MySQL:
Advanced Configuration
Connection Pooling
Optimize database connection pooling for your workload:- Small deployments:
max_open_conn = 10-20,max_idle_conn = 2-5 - Medium deployments:
max_open_conn = 50-100,max_idle_conn = 10-25 - Large deployments:
max_open_conn = 100-200,max_idle_conn = 25-50
High Availability Mode
For multi-instance Grafana deployments:high_availability = false, some features run in-process instead of using the database, which is only safe for single-instance deployments.
Query Logging
Enable SQL query logging for debugging:Migration Settings
Control database migration behavior:Instrumentation and Metrics
Database Maintenance
Backup
PostgreSQL:Restore
PostgreSQL:Database Migration
Migrating from SQLite to PostgreSQL/MySQL:- Export dashboards and configuration
- Set up the new database
- Update Grafana configuration
- Restart Grafana (migrations run automatically)
- Re-import dashboards if needed
Troubleshooting
Connection Issues
Check database connectivity:- Verify database host and port
- Check firewall rules
- Ensure database server is running
- Verify username and password
- Check user permissions
- Review database access controls
- Enable SSL mode in configuration
- Provide SSL certificates if using verify-full
Performance Issues
Too many connections:- Reduce
max_open_conn - Increase database max connections limit
- Check for connection leaks
- Enable
log_queriesto identify slow queries - Optimize database indexes
- Increase database resources (CPU, memory)
- Review connection pool settings
Migration Failures
Migration lock timeout:- Increase
locking_attempt_timeout_sec - Ensure no other Grafana instances are running migrations
- Manually release database locks
- Check Grafana logs for specific error messages
- Verify database user has sufficient privileges
- Ensure database version compatibility
Best Practices
- Use PostgreSQL for production - Better performance and reliability than MySQL/SQLite
- Enable SSL/TLS - Encrypt database connections in production
- Regular backups - Automate database backups and test restores
- Monitor connections - Track connection pool usage and adjust settings
- Enable high availability mode - Required for multi-instance deployments
- Use connection pooling - Configure appropriate pool sizes for your workload
- Separate database server - Don’t run the database on the same host as Grafana in production
- Use secrets management - Store database credentials in environment variables or secret managers
- Monitor database performance - Track query performance and optimize as needed
- Plan for growth - Size your database server for expected data volume and user count