Menu
Grafana Cloud

PostgreSQL integration for Grafana Cloud

PostgreSQL is a free and open-source relational database management system (RDBMS) that emphasizes extensibility and SQL compliance. This integration enables the Grafana agent to send metrics to Grafana Cloud and provides useful alerts and a prebuilt dashboard to help you monitor and visualization them.

The PostgreSQL integration for Grafana Cloud enables you to monitor important database performance metrics such as cache hit ratio, and queries per second. Metrics are emitted by the Postgres Grafana Agent integration.

Before you begin

In order to send metics to Grafana Cloud you must enable the postgres_exporter integration to allow the agent to automatically collect system metrics from the configured postgres server address. For more information, see postgres_exporter_config.

Install PostgreSQL for Grafana Cloud

  1. In your Grafana Cloud instance, click Integrations and Connections (lightning bolt icon), then search or navigate to the PostgreSQL tile.

  2. Click the PostgreSQL tile and click Install Integration

  3. Once the integration is installed, follow the steps on the Configuration Details page to setup Grafana Agent to automatically scrape and send PostgreSQL metrics to your Grafana Cloud instance.

Post-install configuration for PostgreSQL integration

It’s recommend that you configure a separate user for the Grafana agent to give it only the strictly mandatory security privileges necessary for monitoring your node. For more information, see PostgreSQL server exporter documentation.

Note You must replace the placeholder data_source_names to the address of the Postgres servers you want to monitor.

The following example agent configuration assumes the database name is postgres, the user linus and the password 42secret:

integrations:
  postgres_exporter:
    enabled: true
    data_source_names:
      - 'postgresql://linus:42secret@localhost:5432/postgres?sslmode=disable'

For a full description of configuration options, see postgres_exporter_config in the Grafana Agent documentation.

Dashboards

The PostgreSQL integration for Grafana Cloud installs one prebuilt dashboard that allows you to visualize important performance heuristics in real time.

Postgres dashboard example

Alerts

AlertDescription
PostgreSQLMaxConnectionsReachedCritical: Instance has reached maxed Postgres connections
PostgreSQLHighConnectionsWarning: Instance is over 80% of max Postgres connections
PostgreSQLDownCritical: PostgreSQL is not processing queries
PostgreSQLSlowQueriesWarning: PostgreSQL has a high number of slow queries
PostgreSQLQPSWarning: PostgreSQL queries are greater than 10,000 per second
PostgreSQLCacheHitRatioWarning: PostgreSQL low cache hit rate

|

Metrics captured by the PostgreSQL integration for Grafana Cloud

The Grafana agent configuration provided by the integration scrapes all metrics provided by the Grafana agent postgres embedded exporter.

You can see a full list of those metrics, with descriptions, by running the following command:

curl http://<agent hostname>:<agent listen port>/integrations/node_exporter/metrics | sed -nr 's/# HELP ([a-zA-Z0-9_]+) (.*)$/\1 \2/p'

The default PostgreSQL integration dashboard utilizes the following metrics:

  • pg_settings_max_connections Sets the maximum number of concurrent connections.

  • pg_settings_superuser_reserved_connections Sets the number of connection slots reserved for superusers.

  • pg_stat_activity_count number of connections in this state

  • pg_stat_activity_max_tx_duration max duration in seconds any active transaction has been running

  • pg_stat_bgwriter_buffers_alloc Number of buffers allocated

  • pg_stat_bgwriter_buffers_backend Number of buffers written directly by a backend

  • pg_stat_bgwriter_buffers_backend_fsync Number of times a backend had to execute its own fsync call (normally the background writer handles those even when the backend does its own write)

  • pg_stat_bgwriter_buffers_checkpoint Number of buffers written during checkpoints

  • pg_stat_bgwriter_buffers_clean Number of buffers written by the background writer

  • pg_stat_database_blks_hit Number of times disk blocks were found already in the buffer cache, so that a read was not necessary (this only includes hits in the PostgreSQL buffer cache, not the operating system’s file system cache)

  • pg_stat_database_blks_read Number of disk blocks read in this database

  • pg_stat_database_conflicts Number of queries canceled due to conflicts with recovery in this database. (Conflicts occur only on standby servers; see pg_stat_database_conflicts for details.) pg_stat_database_deadlocks Number of deadlocks detected in this database

  • pg_stat_database_numbackends Number of backends currently connected to this database. This is the only column in this view that returns a value reflecting current state; all other columns return the accumulated values since the last reset.

  • pg_stat_database_tup_deleted Number of rows deleted by queries in this database

  • pg_stat_database_tup_fetched Number of rows fetched by queries in this database

  • pg_stat_database_tup_inserted Number of rows inserted by queries in this database

  • pg_stat_database_tup_returned Number of rows returned by queries in this database

  • pg_stat_database_tup_updated Number of rows updated by queries in this database

  • pg_stat_database_xact_commit Number of transactions in this database that have been committed

  • pg_stat_database_xact_rollback Number of transactions in this database that have been rolled back

  • pg_up Whether the last scrape of metrics from PostgreSQL was able to connect to the server (1 for yes, 0 for no).

Cost

By connecting your PostgreSQL integration to Grafana Cloud you might incur charges. For more information, use the following links:

For an increase in the number of active series that your Grafana Cloud account uses for metrics included in each Cloud tier, see Active series and dpm usage and Cloud tier pricing.

Video