Skip to main content
Grafana requires a database to store dashboards, users, organizations, data sources, and other metadata. This guide covers configuring the supported database backends.

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):
Require SSL:
Verify SSL certificate:

PostgreSQL Setup

Create the Grafana database and user:
For PostgreSQL 15+, you may need to grant schema permissions:

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 requires utf8mb4 character set for MySQL:

Advanced Configuration

Connection Pooling

Optimize database connection pooling for your workload:
Recommended values:
  • 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:
When 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:
MySQL:
SQLite:

Restore

PostgreSQL:
MySQL:
SQLite:

Database Migration

Migrating from SQLite to PostgreSQL/MySQL:
  1. Export dashboards and configuration
  2. Set up the new database
  3. Update Grafana configuration
  4. Restart Grafana (migrations run automatically)
  5. Re-import dashboards if needed
For large databases, consider using migration tools or contact Grafana support.

Troubleshooting

Connection Issues

Check database connectivity:
Common errors:
  • 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
Slow queries:
  • Enable log_queries to 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
Migration errors:
  • Check Grafana logs for specific error messages
  • Verify database user has sufficient privileges
  • Ensure database version compatibility

Best Practices

  1. Use PostgreSQL for production - Better performance and reliability than MySQL/SQLite
  2. Enable SSL/TLS - Encrypt database connections in production
  3. Regular backups - Automate database backups and test restores
  4. Monitor connections - Track connection pool usage and adjust settings
  5. Enable high availability mode - Required for multi-instance deployments
  6. Use connection pooling - Configure appropriate pool sizes for your workload
  7. Separate database server - Don’t run the database on the same host as Grafana in production
  8. Use secrets management - Store database credentials in environment variables or secret managers
  9. Monitor database performance - Track query performance and optimize as needed
  10. Plan for growth - Size your database server for expected data volume and user count

Example Configurations

Development (SQLite)

Production (PostgreSQL with SSL)

Docker Compose with PostgreSQL