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

OTELDATADOGDESCRIPTIONFILTER
postgresql.backendspostgresql.connectionsThe number of backends.
postgresql.bgwriter.buffers.allocatedpostgresql.bgwriter.buffers_allocNumber of buffers allocated.
postgresql.bgwriter.buffers.writespostgresql.bgwriter.buffers_backendNumber of buffers written.source: backend
postgresql.bgwriter.buffers.writespostgresql.bgwriter.buffers_backend_fsyncNumber of buffers written.source: backend_fsync
postgresql.bgwriter.buffers.writespostgresql.bgwriter.buffers_checkpointNumber of buffers written.source: checkpoints
postgresql.bgwriter.buffers.writespostgresql.bgwriter.buffers_cleanNumber of buffers written.source: bgwriter
postgresql.bgwriter.checkpoint.countpostgresql.bgwriter.checkpoints_timedThe number of checkpoints performed.type: scheduled
postgresql.bgwriter.checkpoint.countpostgresql.bgwriter.checkpoints_requestedThe number of checkpoints performed.type: requested
postgresql.bgwriter.durationpostgresql.bgwriter.sync_timeTotal time spent writing and syncing files to disk by checkpoints.type: sync
postgresql.bgwriter.durationpostgresql.bgwriter.write_timeTotal time spent writing and syncing files to disk by checkpoints.type: write
postgresql.bgwriter.maxwrittenpostgresql.bgwriter.maxwritten_cleanNumber of times the background writer stopped a cleaning scan because it had written too many buffers.
postgresql.blks_hitpostgresql.buffer_hitNumber of times disk blocks were found already in the buffer cache.
postgresql.blks_readpostgresql.disk_readNumber of disk blocks read in this database.
postgresql.blocks_readpostgresql.heap_blocks_readThe number of blocks read.source: heap_read
postgresql.blocks_readpostgresql.heap_blocks_hitThe number of blocks read.source: heap_hit
postgresql.blocks_readpostgresql.index_blocks_readThe number of blocks read.source: idx_read
postgresql.blocks_readpostgresql.index_blocks_hitThe number of blocks read.source: idx_hit
postgresql.blocks_readpostgresql.toast_blocks_readThe number of blocks read.source: toast_read
postgresql.blocks_readpostgresql.toast_blocks_hitThe number of blocks read.source: toast_hit
postgresql.blocks_readpostgresql.toast_index_blocks_readThe number of blocks read.source: tidx_read
postgresql.blocks_readpostgresql.toast_index_blocks_hitThe number of blocks read.source: tidx_hit
postgresql.commitspostgresql.commitsThe number of commits.
postgresql.connection.maxpostgresql.max_connectionsConfigured maximum number of client connections allowed
postgresql.database.countpostgresql.db.countNumber of user databases.
postgresql.database.lockspostgresql.locksThe number of database locks.
postgresql.db_sizepostgresql.database_sizeThe database disk usage.
postgresql.deadlockspostgresql.deadlocks.countThe number of deadlocks.
postgresql.function.callspostgresql.function.callsThe number of calls made to a function. Requires track_functions=pl|all in Postgres config.
postgresql.index.scanspostgresql.index_scansThe number of index scans on a table.
postgresql.index.sizepostgresql.individual_index_sizeThe size of the index on disk.
postgresql.operationspostgresql.rows_hot_updatedThe number of db row operations.operation: hot_upd
postgresql.replication.data_delaypostgresql.replication_delay_bytesThe amount of data delayed in replication.
postgresql.rollbackspostgresql.rollbacksThe number of rollbacks.
postgresql.rowspostgresql.dead_rowsThe number of rows in the database.state: dead
postgresql.rowspostgresql.live_rowsThe number of rows in the database.state: live
postgresql.sequential_scanspostgresql.seq_scansThe number of sequential scans.
postgresql.table.countpostgresql.table.countNumber of user tables in a database.
postgresql.table.sizepostgresql.table_sizeDisk space used by a table.
postgresql.table.vacuum.countpostgresql.vacuumedNumber of times a table has manually been vacuumed.
postgresql.temp.iopostgresql.temp_bytesTotal amount of data written to temporary files by queries.
postgresql.temp_filespostgresql.temp_filesThe number of temp files.
postgresql.tup_deletedpostgresql.rows_deletedNumber of rows deleted by queries in the database.
postgresql.tup_fetchedpostgresql.rows_fetchedNumber of rows fetched by queries in the database.
postgresql.tup_insertedpostgresql.rows_insertedNumber of rows inserted by queries in the database.
postgresql.tup_returnedpostgresql.rows_returnedNumber of rows returned by queries in the database.
postgresql.tup_updatedpostgresql.rows_updatedNumber of rows updated by queries in the database.
postgresql.wal.agepostgresql.wal_ageAge of the oldest WAL file.
postgresql.wal.delaypostgresql.replication.wal_write_lagTime between flushing recent WAL locally and receiving notification that the standby server has completed an operation with it.operation: write
postgresql.wal.delaypostgresql.replication.wal_flush_lagTime between flushing recent WAL locally and receiving notification that the standby server has completed an operation with it.operation: flush
postgresql.wal.delaypostgresql.replication.wal_replay_lagTime between flushing recent WAL locally and receiving notification that the standby server has completed an operation with it.operation: replay

See OpenTelemetry Metrics Mapping for more information.

Further reading

Additional helpful documentation, links, and articles: