For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/opentelemetry/integrations/postgres_metrics.md. A documentation index is available at /llms.txt.

Overview

The PostgreSQL receiver allows for collection of PostgreSQL metrics and access to the PostgreSQL Overview and PostgreSQL Metrics dashboards. Configure the receiver according to the specifications of the latest version of the postgresqlreceiver.

For more information, see the OpenTelemetry project documentation for the PostgreSQL receiver.

Setup

To collect PostgreSQL metrics with OpenTelemetry for use with Datadog:

  1. Configure the PostgreSQL receiver in your OpenTelemetry Collector configuration.
  2. Optionally, configure the host metrics receiver if your OpenTelemetry Collector is running on the same server as your PostgreSQL database.
  3. Optionally, configure the file log receiver if your OpenTelemetry Collector is running on the same server as your PostgreSQL database.
  4. Configure service pipelines.
  5. Ensure the OpenTelemetry Collector is configured to export to Datadog.

PostgreSQL receiver

receivers:
  postgresql/pg-host-1:
    endpoint: "<HOST>:<PORT>"
    username: "<USERNAME>"
    password: "<PASSWORD>"
    collection_interval: 15s
    metrics:
      postgresql.blks_hit:
        enabled: true
      postgresql.blks_read:
        enabled: true
      postgresql.database.locks:
        enabled: true
      postgresql.deadlocks:
        enabled: true
      postgresql.function.calls:
        enabled: true
      postgresql.sequential_scans:
        enabled: true
      postgresql.temp_files:
        enabled: true
      postgresql.temp.io:
        enabled: true
      postgresql.tup_deleted:
        enabled: true
      postgresql.tup_fetched:
        enabled: true
      postgresql.tup_inserted:
        enabled: true
      postgresql.tup_returned:
        enabled: true
      postgresql.tup_updated:
        enabled: true
      postgresql.wal.delay:
        enabled: true

processors:
  resource/pg-host-1:
    attributes:
      - action: insert
        key: datadog.host.name
        value: <HOST>
  cumulativetodelta: {}
  deltatorate:
    metrics:
      - postgresql.tup_returned
      - postgresql.tup_fetched
      - postgresql.tup_inserted
      - postgresql.tup_updated
      - postgresql.tup_deleted
      - postgresql.operations
      - postgresql.commits
      - postgresql.rollbacks
      - postgresql.blks_hit
      - postgresql.blks_read
      - postgresql.temp_files
      - postgresql.temp.io
      - postgresql.function.calls
      - postgresql.index.scans
      - postgresql.sequential_scans
      - postgresql.blocks_read

See the PostgreSQL receiver documentation for detailed configuration options and requirements.

Host metrics receiver

receivers:
  hostmetrics:
    scrapers:
      load:
      cpu:
        metrics:
         system.cpu.utilization:
           enabled: true
      memory:
      network:

File log receiver

This example assumes PostgreSQL 15+ with log_destination = 'jsonlog' configured. If you use the default stderr log format, adjust the operators to match your log_line_prefix.

receivers:
  filelog:
    include:
      - <PATH_TO_YOUR_POSTGRESQL_LOG>
    operators:
      - type: json_parser
        parse_from: body
        timestamp:
          parse_from: attributes.timestamp
          layout: "%Y-%m-%d %H:%M:%S.%L %Z"

processors:
  transform/logs:
    log_statements:
      - context: resource
        statements:
          - set(attributes["datadog.host.name"], "<HOST>")
          - set(attributes["datadog.log.source"], "postgresql")

  batch: {}

Service pipelines

service:
  pipelines:
    metrics/pg-host-1:
      receivers: [postgresql/pg-host-1]
      processors: [resource/pg-host-1, cumulativetodelta, deltatorate]
      exporters: [datadog/exporter]

If you configured the host metrics receiver, add it to a separate metrics pipeline:

    metrics/host:
      receivers: [hostmetrics]
      processors: [cumulativetodelta]
      exporters: [datadog/exporter]

If you configured the file log receiver, add a logs pipeline:

    logs:
      receivers: [filelog]
      processors: [transform/logs, batch]
      exporters: [datadog/exporter]

Data collected

OTELDESCRIPTIONFILTER
postgresql.backendsThe number of backends.
postgresql.bgwriter.buffers.allocatedNumber of buffers allocated.
postgresql.bgwriter.buffers.writesNumber of buffers written.source: backend
postgresql.bgwriter.buffers.writesNumber of buffers written.source: backend_fsync
postgresql.bgwriter.buffers.writesNumber of buffers written.source: checkpoints
postgresql.bgwriter.buffers.writesNumber of buffers written.source: bgwriter
postgresql.bgwriter.checkpoint.countThe number of checkpoints performed.type: scheduled
postgresql.bgwriter.checkpoint.countThe number of checkpoints performed.type: requested
postgresql.bgwriter.durationTotal time spent writing and syncing files to disk by checkpoints.type: sync
postgresql.bgwriter.durationTotal time spent writing and syncing files to disk by checkpoints.type: write
postgresql.bgwriter.maxwrittenNumber of times the background writer stopped a cleaning scan because it had written too many buffers.
postgresql.blks_hitNumber of times disk blocks were found already in the buffer cache.
postgresql.blks_readNumber of disk blocks read in this database.
postgresql.blocks_readThe number of blocks read.source: heap_read
postgresql.blocks_readThe number of blocks read.source: heap_hit
postgresql.blocks_readThe number of blocks read.source: idx_read
postgresql.blocks_readThe number of blocks read.source: idx_hit
postgresql.blocks_readThe number of blocks read.source: toast_read
postgresql.blocks_readThe number of blocks read.source: toast_hit
postgresql.blocks_readThe number of blocks read.source: tidx_read
postgresql.blocks_readThe number of blocks read.source: tidx_hit
postgresql.commitsThe number of commits.
postgresql.connection.maxConfigured maximum number of client connections allowed
postgresql.database.countNumber of user databases.
postgresql.database.locksThe number of database locks.
postgresql.db_sizeThe database disk usage.
postgresql.deadlocksThe number of deadlocks.
postgresql.function.callsThe number of calls made to a function. Requires track_functions=pl|all in Postgres config.
postgresql.index.scansThe number of index scans on a table.
postgresql.index.sizeThe size of the index on disk.
postgresql.operationsThe number of db row operations.operation: hot_upd
postgresql.replication.data_delayThe amount of data delayed in replication.
postgresql.rollbacksThe number of rollbacks.
postgresql.rowsThe number of rows in the database.state: dead
postgresql.rowsThe number of rows in the database.state: live
postgresql.sequential_scansThe number of sequential scans.
postgresql.table.countNumber of user tables in a database.
postgresql.table.sizeDisk space used by a table.
postgresql.table.vacuum.countNumber of times a table has manually been vacuumed.
postgresql.temp.ioTotal amount of data written to temporary files by queries.
postgresql.temp_filesThe number of temp files.
postgresql.tup_deletedNumber of rows deleted by queries in the database.
postgresql.tup_fetchedNumber of rows fetched by queries in the database.
postgresql.tup_insertedNumber of rows inserted by queries in the database.
postgresql.tup_returnedNumber of rows returned by queries in the database.
postgresql.tup_updatedNumber of rows updated by queries in the database.
postgresql.wal.ageAge of the oldest WAL file.
postgresql.wal.delayTime between flushing recent WAL locally and receiving notification that the standby server has completed an operation with it.operation: write
postgresql.wal.delayTime between flushing recent WAL locally and receiving notification that the standby server has completed an operation with it.operation: flush
postgresql.wal.delayTime between flushing recent WAL locally and receiving notification that the standby server has completed an operation with it.operation: replay

For the full mapping between OpenTelemetry and Datadog metric names, see OpenTelemetry Metrics Mapping.

Further reading

Additional helpful documentation, links, and articles: