Configure the PostgreSQL data source | Grafana documentation (original) (raw)

Grafana Cloud Enterprise Open source RSS

This document provides instructions for configuring the PostgreSQL data source and explains available configuration options. For general information on managing data sources refer toData source management.

Before you begin

You must have the Organization administrator role to configure the Postgres data source. Organization administrators can alsoconfigure 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.

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 as USE otherdb; or DROP 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:

  1. Click Connections in the left-side menu.
  2. Click Add new connection
  3. Type PostgreSQL in the search bar.
  4. Select the PostgreSQL data source.
  5. 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 - Only for Grafana Cloud users. Private data source connect, or PDC, allows you to establish a private, secured connection between a Grafana Cloud instance, or stack, and data sources secured within a private network. Click the drop-down to locate the URL for PDC. For more information regarding Grafana PDC refer toPrivate data source connect (PDC).

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:

Identifier Description
y year
M month
w week
d day
h hour
m minute
s second
ms millisecond

Provision the data source

You can define and configure the data source in YAML files withprovisioning. For more information about provisioning, and available configuration options, refer toProvision 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: