Configure the PostgreSQL data source
This document provides instructions for configuring the PostgreSQL data source and explains available configuration options. For general information on managing data sources refer to Data source management.
Before you begin
You must have the
Organization administrator
role to configure the Postgres data source. Organization administrators can also configure the data source via YAML with the Grafana provisioning system.Grafana comes with a built-in PostgreSQL data source plugin, eliminating the need to install a plugin.
Familiarize yourself with your PostgreSQL security configuration and gather any necessary security certificates, client certificates, and client keys.
Know which version of PostgreSQL you are running. You will be prompted for this information during the configuration process.
Note
When adding a data source, the database user you specify should have only
SELECT
permissions on the relevant database and tables. Grafana does not validate the safety of queries, which means they can include potentially harmful SQL statements, such asUSE otherdb;
orDROP TABLE user;
, that could be executed. To mitigate this risk, Grafana strongly recommends creating a dedicated PostgreSQL user with restricted permissions.
Example:
CREATE USER grafanareader WITH PASSWORD 'password';
GRANT USAGE ON SCHEMA schema TO grafanareader;
GRANT SELECT ON schema.table TO grafanareader;
Add the PostgreSQL data source
Complete the following steps to set up a new PostgreSQL data source:
- Click Connections in the left-side menu.
- Click Add new connection
- Type
PostgreSQL
in the search bar. - Select the PostgreSQL data source.
- Click Add new data source in the upper right.
You are taken to the Settings tab where you will configure the data source.
PostgreSQL configuration options
Following is a list of PostgreSQL configuration options:
Connection section:
Authentication section:
TLS/SSL Auth Details:
If you select the TLS/SSL Mode options require, verify-ca or verify-full and file system path the following are required:
If you select the TLS/SSL Mode option require and TLS/SSL Method certificate content the following are required:
If you select the TLS/SSL Mode options verify-ca or verify-full with the TLS/SSL Method certificate content the following are required:
PostgreSQL Options:
Connection limits:
Private data source connect:
Click Manage private data source connect to be taken to your PDC connection page, where you’ll find your PDC configuration details.
After you have added your PostgreSQL connection settings, click Save & test to test and save the data source connection.
Min time interval
The Min time interval setting defines a lower limit for the
$__interval
and
$__interval_ms
variables.
This option can also be configured or overridden in the dashboard panel under the data source settings.
This value must be formatted as a number followed by a valid time identifier:
Provision the data source
You can define and configure the data source in YAML files with provisioning. For more information about provisioning, and available configuration options, refer to Provision Grafana.
PostgreSQL provisioning example
apiVersion: 1
datasources:
- name: Postgres
type: postgres
url: localhost:5432
user: grafana
secureJsonData:
password: 'Password!'
jsonData:
database: grafana
sslmode: 'disable' # disable/require/verify-ca/verify-full
maxOpenConns: 100
maxIdleConns: 100
maxIdleConnsAuto: true
connMaxLifetime: 14400
postgresVersion: 903 # 903=9.3, 904=9.4, 905=9.5, 906=9.6, 1000=10
timescaledb: false
Troubleshoot provisioning issues
If you encounter metric request errors or other issues:
- Ensure that the parameters in your data source YAML file precisely match the example provided, including parameter names and the correct use of quotation marks.
- Verify that the database name IS NOT included in the URL.