databases section defines database connections. Each database is identified by a key name that you reference in queries.
Basic Configuration
Configuration Options
Database connection details. Can be provided as a DSN string or as a structured object.See DSN Format below for details.
Configuration for the database connection pool.
Optional list of SQL queries to run immediately after database connection. This can be used to set up connection-wise parameters and configurations.
Optional mapping of label names and values to tag metrics collected from each database. When labels are used, all databases must define the same set of labels.Label names must match the pattern
^[a-zA-Z_][a-zA-Z0-9_]*$.DSN Format
The DSN (Data Source Name) defines how to connect to your database. It can be specified in two ways:String Format
A connection URL string following the SQLAlchemy format:Object Format
A structured object with separate fields:The database dialect and optional driver in the format
dialect[+driver].Examples: postgresql, postgresql+psycopg2, mysql+pymysql, sqliteDatabase username.
Database password. Automatically URL-encoded when using object format.
Database host address.
Database port number. Must be between 1 and 65535.
Database name.
Additional database-specific connection options as key-value pairs.
The object format automatically handles URL encoding, making it easier to use passwords and options with special characters.
Database Dialects
Query Exporter uses SQLAlchemy and supports multiple database engines:- PostgreSQL:
postgresql://orpostgresql+psycopg2:// - MySQL:
mysql://ormysql+pymysql:// - SQLite:
sqlite://(in-memory) orsqlite:///path/to/db - Microsoft SQL Server:
mssql+pymssql:// - Oracle:
oracle+oracledb:// - IBM DB2:
db2:// - ClickHouse:
clickhouse+native:// - Teradata:
teradatasql://
Additional Python packages may be required for specific database drivers. See the SQLAlchemy documentation for details.
Connection Pool
The connection pool manages database connections efficiently:- Up to 5 connections are maintained open
- Up to 10 additional temporary connections can be created during high load
- Total maximum connections: 15
The default connection pool has
size: 1 and max-overflow: 0, meaning only one connection is used.