---
title: Configure PostgreSQL monitoring with OpenTelemetry Collector (CNCF)
source: https://docs.newrelic.com/docs/opentelemetry/db360/postgresql/cncf
---

You can use the OpenTelemetry Collector Contrib for PostgreSQL to monitor your instance. The OpenTelemetry Collector Contrib is a community-supported project that collects telemetry data from PostgreSQL and sends it to New Relic.

By default, the OpenTelemetry Collector Contrib collects limited metrics from PostgreSQL. To send query performance, wait-event, session, and client metrics, you'll need to configure the OpenTelemetry Collector Contrib. This guide shows you how to configure it to collect advanced metrics from PostgreSQL and send them to New Relic.

> #### 💡 NOTE
>
> This page covers the community `postgresql` receiver shipped in the standard `otelcol-contrib` binary. If you're using New Relic's distribution (NRDOT), see [Introduction to PostgreSQL monitoring](https://docs.newrelic.com/docs/opentelemetry/db360/postgresql/introduction) instead.

## Prerequisites [#prerequisites]

-   OpenTelemetry Collector Contrib (`otelcol-contrib`) installed and configured on your system. You can download the latest release from the [OpenTelemetry Collector releases](https://github.com/open-telemetry/opentelemetry-collector-releases/releases) page.
-   `pg_stat_statements` enabled via `shared_preload_libraries` on the monitored PostgreSQL instance. This is required for query performance, wait-event, session, and client data. See [Recommended server parameters](https://docs.newrelic.com/docs/opentelemetry/db360/postgresql/compatibility#params).
-   The collector started in semantic-convention mode using the `receiver.postgresql.useOTelSemconv` feature gate.

    If you're running `otelcol-contrib` as an RPM/Debian package (systemd service), the service file imports environment variables via `EnvironmentFile=/etc/otelcol-contrib/otelcol-contrib.conf`. In that file, append the flag to `OTELCOL_OPTIONS`:

    ```bash
    OTELCOL_OPTIONS="--config=/etc/otelcol-contrib/config.yaml --feature-gates=receiver.postgresql.useOTelSemconv"
    ```

    After saving the file, restart the service to apply the gate:

    ```bash
    sudo systemctl restart otelcol-contrib
    ```

## Enable UI metrics [#enable]

You can enrich your New Relic platform experience by adding and enabling metrics in your `otelcol-contrib` configuration file. Using the configuration provided in this section, you can populate data for the following pages in the New Relic platform:

-   Overview
-   Query performance
-   Wait events
-   Sessions
-   Clients

**Enable Overview page metrics**

The Overview page displays a high-level view of your PostgreSQL instance, including key metrics such as database locks, deadlocks, function calls, query conflicts, sequential scans, and temporary file/IO usage.

To populate data for the Overview page in the New Relic platform, add the following configuration to your `otelcol-contrib` configuration file:

```yaml
receivers:
  postgresql:
    metrics:
      postgresql.database.locks:
        enabled: true
      postgresql.deadlocks:
        enabled: true
      postgresql.function.calls:
        enabled: true
      postgresql.query.conflicts:
        enabled: true
      postgresql.sequential_scans:
        enabled: true
      postgresql.temp.io:
        enabled: true
      postgresql.temp_files:
        enabled: true
```

**Enable Query performance, session, wait, and client metrics**

To populate data for the Query performance, Wait events, Sessions, and Clients pages:

-   Query performance: displays detailed information about the queries running on your PostgreSQL instance in the following tabs:
    -   Normalized queries: displays execution and average CPU time graphs.
    -   Query samples: displays individual query executions including start time, duration, wait type, wait time, database, DB user, and client host.
-   Wait events: displays information about the wait events occurring on your PostgreSQL instance. The query samples view shows queries currently waiting, along with their wait type and wait time.
-   Sessions: visualizes trends for active vs. idle database connections, average session duration, blocked sessions, and usage by application and process, to track load spikes and connection bottlenecks.
-   Clients: displays information about the clients connected to your PostgreSQL instance, including active sessions, blocked sessions, connected DB users, and client host details.

Add the following configuration to your `otelcol-contrib` configuration file:

```yaml
receivers:
  postgresql:
    events:
      db.server.top_query:
        enabled: true
      db.server.query_sample:
        enabled: true
      db.server.query_plan:
        enabled: true
    top_query_collection:
      max_rows_per_query: 1000
      top_n_query: 200
      collection_interval: 60s
    query_sample_collection:
      max_rows_per_query: 1000
```

> #### ⚠️ IMPORTANT
>
> `db.server.query_plan` requires at least one of `db.server.top_query` or `db.server.query_sample` to also be enabled. Enabling it alone is a config validation error.

> #### 💡 NOTE
>
> `postgresql.session.duration` isn't available in the community `postgresql` receiver, so the Sessions table doesn't render on the Sessions page.

## Restart the OpenTelemetry Collector [#restart]

Restart the OpenTelemetry Collector to apply the configuration changes:

```bash
sudo systemctl restart otelcol-contrib
```

## Related documentation [#related]

[Introduction to PostgreSQL monitoring with NRDOT](https://docs.newrelic.com/docs/opentelemetry/db360/postgresql/introduction)

Learn about all the available installation methods for PostgreSQL monitoring with New Relic.

[Metrics reference](https://docs.newrelic.com/docs/opentelemetry/db360/postgresql/metrics-reference)

Learn about the available metrics collected by the NRDOT Collector.
