Supported OS Linux Windows Mac OS

インテグレーションバージョン14.2.0

PostgreSQL Graph

概要

Postgres インテグレーションは、Postgres データベースの健全性とパフォーマンスに関するメトリクスをほぼリアルタイムで提供します。提供されるダッシュボードでこれらのメトリクスを可視化するとともに、モニターを作成して PostgreSQL の状態についてチームに警告を発することができます。

データベースモニタリング (DBM) を有効にすると、クエリのパフォーマンスとデータベースの健全性について詳細なインサイトを取得できます。標準のインテグレーションに加え、Datadog DBM では、クエリレベルのメトリクス、リアルタイムおよび過去のクエリスナップショット、待機イベントの分析情報、データベースの負荷、クエリ実行計画、ブロッキングを引き起こしているクエリについてのインサイトが提供されます。

セットアップ

このページでは、標準的な Postgres Agent のインテグレーションについて説明します。Postgres のデータベースモニタリング製品をお求めの場合は、Datadog データベースモニタリングをご覧ください。

インストール

PostgreSQL チェックは Agent にパッケージ化されています。PostgreSQL メトリクスとログの収集を開始するには、Agent をインストールします

コンフィギュレーション

: PostgreSQL 用のデータベースモニタリングをインストールするには、データベースモニタリングドキュメントでご利用のホスティングソリューションを選択して、手順を確認してください。

標準のインテグレーションを単体でインストールする場合のみ、このガイドの下記の手順に進んでください。

Postgres の準備

標準の PostgreSQL インテグレーションを開始するには、PostgreSQL サーバーへの適切なアクセス権を持つ読み取り専用 datadog ユーザーを作成します。PostgreSQL データベースで psql を起動します。

PostgreSQL バージョン 10 以上の場合、次を実行します。

create user datadog with password '<PASSWORD>';
grant pg_monitor to datadog;
grant SELECT ON pg_stat_database to datadog;

それより前の PostgreSQL バージョンの場合、次を実行します。

create user datadog with password '<パスワード>';
grant SELECT ON pg_stat_database to datadog;

アクセス許可が正しいことを確認するには、次のコマンドを実行します。

psql -h localhost -U datadog postgres -c \
"select * from pg_stat_database LIMIT(1);" \
&& echo -e "\e[0;32mPostgres connection - OK\e[0m" \
|| echo -e "\e[0;31mCannot connect to Postgres\e[0m"

パスワードの入力を要求された場合は、最初のコマンドで使用したパスワードを入力します。

: PostgreSQL バージョン 9.6 以前で pg_stat_activity から読み取るには、次のコマンドを実行して SECURITY DEFINER を作成します。

CREATE FUNCTION pg_stat_activity() RETURNS SETOF pg_catalog.pg_stat_activity AS
$$ SELECT * from pg_catalog.pg_stat_activity; $$
LANGUAGE sql VOLATILE SECURITY DEFINER;

CREATE VIEW pg_stat_activity_dd AS SELECT * FROM pg_stat_activity();
grant SELECT ON pg_stat_activity_dd to datadog;

: その他の表へのクエリを必要とするカスタムメトリクスを生成する際は、datadog ユーザーにそれらの表への SELECT 権限を付与する必要があります。例: grant SELECT on <TABLE_NAME> to datadog;。詳しくは、よくあるご質問セクションをご確認ください。

ホスト

ホストで実行中の Agent に対してこのチェックを構成するには:

メトリクスの収集
  1. postgres.d/conf.yaml ファイルを編集して、host / port を指定し、監視するマスターを設定します。使用可能なすべてのコンフィギュレーションオプションについては、サンプル postgres.d/conf.yaml を参照してください。

    init_config:
    
    instances:
      ## @param host - string - required
      ## The hostname to connect to.
      ## NOTE: Even if the server name is "localhost", the agent connects to
      ## PostgreSQL using TCP/IP, unless you also provide a value for the sock key.
      #
      - host: localhost
    
        ## @param port - integer - required
        ## Port to use when connecting to PostgreSQL.
        #
        port: 5432
    
        ## @param user - string - required
        ## Datadog Username created to connect to PostgreSQL.
        #
        username: datadog
    
        ## @param pass - string - required
        ## Password associated with the Datadog user.
        #
        password: "<PASSWORD>"
    
        ## @param dbname - string - optional - default: postgres
        ## Name of the PostgresSQL database to monitor.
        ## Note: If omitted, the default system postgres database is queried.
        #
        dbname: "<DB_NAME>"
    
        # @param disable_generic_tags - boolean - optional - default: false
        # The integration will stop sending server tag as is reduntant with host tag
        disable_generic_tags: true
    
  2. Agent を再起動します

トレースの収集

Datadog APM は Postgres を統合して、分散システム全体のトレースを確認します。Datadog Agent v6 以降では、トレースの収集はデフォルトで有効化されています。トレースの収集を開始するには、以下の手順に従います。

  1. Datadog でトレースの収集を有効にします
  2. Postgres へのリクエストを作成するアプリケーションをインスツルメントします
ログの収集

Agent バージョン 6.0 以降で利用可能

PostgreSQL のデフォルトのログは stderr に記録され、ログに詳細な情報は含まれません。ログ行のプレフィックスに指定された詳細を追加してファイルに記録することをお勧めします。詳細は PostgreSQL のドキュメントエラーレポートとログを参照してください。

  1. ロギングはファイル /etc/postgresql/<バージョン>/main/postgresql.conf 内で構成されます。ステートメント出力を含む通常のログ結果の場合、ログセクションの次のパラメーターのコメントを外します。

      logging_collector = on
      log_directory = 'pg_log'  # directory where log files are written,
                                # can be absolute or relative to PGDATA
      log_filename = 'pg.log'   # log file name, can include pattern
      log_statement = 'all'     # log all queries
      #log_duration = on
      log_line_prefix= '%m [%p] %d %a %u %h %c '
      log_file_mode = 0644
      ## For Windows
      #log_destination = 'eventlog'
    
  2. 詳細な期間メトリクスを収集し、Datadog インターフェースで検索可能にするには、ステートメント自体を使用してインラインで構成する必要があります。上記の例と推奨コンフィギュレーションとの違いについては、以下を参照してください。: log_statementlog_duration` オプションは両方ともコメントアウトされています。このトピックについては、statement/duration のログを同一行に記録するを参照してください。

    この構成では、すべてのステートメントをログに記録します。期間に応じて出力を減らすには、log_min_duration_statement の値を希望の最小期間 (ミリ秒単位) に設定します。

      log_min_duration_statement = 0    # -1 is disabled, 0 logs all statements
                                        # and their durations, > 0 logs only
                                        # statements running at least this number
                                        # of milliseconds
      #log_statement = 'all'
      #log_duration = on
    
  3. Datadog Agent で、ログの収集はデフォルトで無効になっています。以下のように、datadog.yaml ファイルでこれを有効にします。

    logs_enabled: true
    
  4. PostgreSQL のログの収集を開始するには、次の構成ブロックを postgres.d/conf.yaml ファイルに追加し、編集します。

    logs:
      - type: file
        path: "<LOG_FILE_PATH>"
        source: postgresql
        service: "<SERVICE_NAME>"
        #To handle multi line that starts with yyyy-mm-dd use the following pattern
        #log_processing_rules:
        #  - type: multi_line
        #    pattern: \d{4}\-(0?[1-9]|1[012])\-(0?[1-9]|[12][0-9]|3[01])
        #    name: new_log_start_with_date
    

    service パラメーターと path パラメーターの値を変更し、環境に合わせて構成してください。使用可能なすべてのコンフィギュレーションオプションについては、サンプル postgres.d/conf.yaml を参照してください。

  5. Agent を再起動します

Docker

コンテナで実行中の Agent に対してこのチェックを構成するには:

メトリクスの収集

アプリケーションのコンテナで、オートディスカバリーのインテグレーションテンプレートを Docker ラベルとして設定します。

LABEL "com.datadoghq.ad.check_names"='["postgres"]'
LABEL "com.datadoghq.ad.init_configs"='[{}]'
LABEL "com.datadoghq.ad.instances"='[{"host":"%%host%%", "port":5432,"username":"datadog","password":"<PASSWORD>"}]'
ログの収集

Datadog Agent で、ログの収集はデフォルトで無効になっています。有効にする方法については、Docker ログ収集を参照してください。

次に、ログインテグレーションを Docker ラベルとして設定します。

LABEL "com.datadoghq.ad.logs"='[{"source":"postgresql","service":"postgresql"}]'
トレースの収集

コンテナ化されたアプリケーションの APM は、Agent v6 以降でサポートされていますが、トレースの収集を開始するには、追加のコンフィギュレーションが必要です。

Agent コンテナで必要な環境変数

パラメーター
<DD_API_KEY>api_key
<DD_APM_ENABLED>true
<DD_APM_NON_LOCAL_TRAFFIC>true

利用可能な環境変数およびコンフィギュレーションの全リストについては、Docker アプリケーションのトレース を参照してください。

次に、Postgres にリクエストを送信するアプリケーションのコンテナをインスツルメントし、Agent のコンテナ名に DD_AGENT_HOST を設定します。

Kubernetes

このチェックを、Kubernetes で実行している Agent に構成します。

メトリクスの収集

アプリケーションのコンテナで、オートディスカバリーのインテグレーションテンプレートをポッドアノテーションとして設定します。他にも、ファイル、ConfigMap、または key-value ストアを使用してテンプレートを構成できます。

Annotations v1 (Datadog Agent < v7.36 向け)

apiVersion: v1
kind: Pod
metadata:
  name: postgres
  annotations:
    ad.datadoghq.com/postgresql.check_names: '["postgres"]'
    ad.datadoghq.com/postgresql.init_configs: '[{}]'
    ad.datadoghq.com/postgresql.instances: |
      [
        {
          "host": "%%host%%",
          "port":"5432",
          "username":"datadog",
          "password":"<PASSWORD>"
        }
      ]      
spec:
  containers:
    - name: postgres

Annotations v2 (Datadog Agent v7.36+ 向け)

apiVersion: v1
kind: Pod
metadata:
  name: postgres
  annotations:
    ad.datadoghq.com/postgres.checks: |
      {
        "postgres": {
          "init_config": {},
          "instances": [
            {
              "host": "%%host%%",
              "port":"5432",
              "username":"datadog",
              "password":"<PASSWORD>"
            }
          ]
        }
      }      
spec:
  containers:
    - name: postgres
ログの収集

Datadog Agent で、ログの収集はデフォルトで無効になっています。有効にする方法については、Kubernetes ログ収集を参照してください。

次に、ログのインテグレーションをポッドアノテーションとして設定します。これは、ファイル、ConfigMap、または key-value ストアを使用して構成することも可能です。

Annotations v1/v2

apiVersion: v1
kind: Pod
metadata:
  name: postgres
  annotations:
    ad.datadoghq.com/postgres.logs: '[{"source":"postgresql","service":"<SERVICE_NAME>"}]'
spec:
  containers:
    - name: postgres
トレースの収集

コンテナ化されたアプリケーションの APM は、Agent v6 以降を実行するホストでサポートされていますが、トレースの収集を開始するには、追加のコンフィギュレーションが必要です。

Agent コンテナで必要な環境変数

パラメーター
<DD_API_KEY>api_key
<DD_APM_ENABLED>true
<DD_APM_NON_LOCAL_TRAFFIC>true

利用可能な環境変数とコンフィギュレーションの完全なリストについては、Kubernetes アプリケーションのトレースおよび Kubernetes DaemonSet のセットアップを参照してください。

そして、Postgres へのリクエストを作成するアプリケーションコンテナをインスツルメントします

ECS

このチェックを、ECS で実行している Agent に構成するには:

メトリクスの収集

アプリケーションのコンテナで、オートディスカバリーのインテグレーションテンプレートを Docker ラベルとして設定します。

{
  "containerDefinitions": [{
    "name": "postgres",
    "image": "postgres:latest",
    "dockerLabels": {
      "com.datadoghq.ad.check_names": "[\"postgres\"]",
      "com.datadoghq.ad.init_configs": "[{}]",
      "com.datadoghq.ad.instances": "[{\"host\":\"%%host%%\", \"port\":5432,\"username\":\"datadog\",\"password\":\"<PASSWORD>\"}]"
    }
  }]
}
ログの収集

Datadog Agent で、ログの収集はデフォルトで無効になっています。有効にする方法については、ECS ログ収集を参照してください。

次に、ログインテグレーションを Docker ラベルとして設定します。

{
  "containerDefinitions": [{
    "name": "postgres",
    "image": "postgres:latest",
    "dockerLabels": {
      "com.datadoghq.ad.logs": "[{\"source\":\"postgresql\",\"service\":\"postgresql\"}]"
    }
  }]
}
トレースの収集

コンテナ化されたアプリケーションの APM は、Agent v6 以降でサポートされていますが、トレースの収集を開始するには、追加のコンフィギュレーションが必要です。

Agent コンテナで必要な環境変数

パラメーター
<DD_API_KEY>api_key
<DD_APM_ENABLED>true
<DD_APM_NON_LOCAL_TRAFFIC>true

利用可能な環境変数およびコンフィギュレーションの全リストについては、Docker アプリケーションのトレース を参照してください。

次に、Postgres にリクエストを送信するアプリケーションのコンテナをインスツルメントし、EC2 プライベート IP アドレスDD_AGENT_HOST を設定します。

検証

Agent の status サブコマンドを実行し、Checks セクションで postgres を探します。

収集データ

以下に記載されているメトリクスのいくつかには、追加の構成が必要です。すべての構成オプションについては、サンプル postgres.d/conf.yaml を参照してください。

メトリクス

postgresql.connections
(gauge)
The number of active connections to this database. If DBM is enabled, this metric is tagged with state, app, db and user
Shown as connection
postgresql.commits
(gauge)
The number of transactions that have been committed in this database.
Shown as transaction
postgresql.rollbacks
(gauge)
The number of transactions that have been rolled back in this database.
Shown as transaction
postgresql.disk_read
(gauge)
The number of disk blocks read in this database.
Shown as block
postgresql.buffer_hit
(gauge)
The number of times disk blocks were found in the buffer cache, preventing the need to read from the database.
Shown as hit
postgresql.rows_returned
(gauge)
The number of rows returned by queries in this database
Shown as row
postgresql.rows_fetched
(gauge)
The number of rows fetched by queries in this database
Shown as row
postgresql.rows_inserted
(gauge)
The number of rows inserted by queries in this database
Shown as row
postgresql.rows_updated
(gauge)
The number of rows updated by queries in this database
Shown as row
postgresql.rows_deleted
(gauge)
The number of rows deleted by queries in this database
Shown as row
postgresql.database_size
(gauge)
The disk space used by this database.
Shown as byte
postgresql.db.count
(gauge)
The number of available databases.
Shown as item
postgresql.deadlocks
(gauge)
The rate of deadlocks detected in this database
Shown as lock
postgresql.deadlocks.count
(count)
The number of deadlocks detected in this database
Shown as lock
postgresql.temp_bytes
(gauge)
The amount of data written to temporary files by queries in this database.
Shown as byte
postgresql.temp_files
(gauge)
The number of temporary files created by queries in this database.
Shown as file
postgresql.bgwriter.checkpoints_timed
(count)
The number of scheduled checkpoints that were performed.
postgresql.bgwriter.checkpoints_requested
(count)
The number of requested checkpoints that were performed.
postgresql.bgwriter.buffers_checkpoint
(count)
The number of buffers written during checkpoints.
postgresql.bgwriter.buffers_clean
(count)
The number of buffers written by the background writer.
postgresql.bgwriter.maxwritten_clean
(count)
The number of times the background writer stopped a cleaning scan due to writing too many buffers.
postgresql.bgwriter.buffers_backend
(count)
The number of buffers written directly by a backend.
Shown as buffer
postgresql.bgwriter.buffers_alloc
(count)
The number of buffers allocated
postgresql.bgwriter.buffers_backend_fsync
(count)
The of times a backend had to execute its own fsync call instead of the background writer.
postgresql.bgwriter.write_time
(count)
The total amount of checkpoint processing time spent writing files to disk.
Shown as millisecond
postgresql.bgwriter.sync_time
(count)
The total amount of checkpoint processing time spent synchronizing files to disk.
Shown as millisecond
postgresql.conflicts.tablespace
(count)
Number of queries in this database that have been canceled due to dropped tablespaces. This will occur when a temp_tablespace is dropped while being used on a standby.
Shown as query
postgresql.conflicts.lock
(count)
Number of queries in this database that have been canceled due to lock timeouts. This will occur when the walreceiver process tries to apply a change requiring an ACCESS EXCLUSIVE lock (drop table, truncate...) while a query on the replica is reading the table (holding an ACCESS SHARE lock). The conflicting query will be killed after waiting up to maxstandbystreaming_delay seconds.
Shown as query
postgresql.conflicts.snapshot
(count)
Number of queries in this database that have been canceled due to old snapshots. Snapshot conflict will occur when a VACUUM is replayed, removing tuples currently read on a standby.
Shown as query
postgresql.conflicts.bufferpin
(count)
Number of queries in this database that have been canceled due to pinned buffers. Buffer pin conflicts will occur when the walreceiver process tries to apply a buffer cleanup like HOT chain pruning. This require a complete lock of the buffer and any query pinning the buffer will conflict with the cleaning.
Shown as query
postgresql.conflicts.deadlock
(count)
Number of queries in this database that have been canceled due to deadlocks. Deadlock conflicts will happen when the walreceiver tries to apply a buffer like HOT chain pruning. If the conflict takes more than deadlock_timeout seconds, a deadlock check will be triggered and conflicting queries will be canceled until the buffer is unpinned.
Shown as query
postgresql.locks
(gauge)
The number of locks active for this database.
Shown as lock
postgresql.seq_scans
(gauge)
The number of sequential scans initiated on this table.
Shown as scan
postgresql.seq_rows_read
(gauge)
The number of live rows fetched by sequential scans.
Shown as row
postgresql.index_scans
(gauge)
The number of index scans initiated on this table, tagged by index.
Shown as scan
postgresql.index_rel_scans
(gauge)
The overall number of index scans initiated on this table.
Shown as scan
postgresql.index_rows_fetched
(gauge)
The number of live rows fetched by index scans.
Shown as row
postgresql.index_rel_rows_fetched
(gauge)
The number of live rows fetched by index scans.
Shown as row
postgresql.rows_hot_updated
(gauge)
The number of rows HOT updated, meaning no separate index update was needed.
Shown as row
postgresql.live_rows
(gauge)
The estimated number of live rows.
Shown as row
postgresql.dead_rows
(gauge)
The estimated number of dead rows.
Shown as row
postgresql.vacuumed
(count)
The number of times this table has been manually vacuumed.
postgresql.autovacuumed
(count)
The number of times this table has been vacuumed by the autovacuum daemon.
postgresql.analyzed
(count)
The number of times this table has been manually analyzed.
postgresql.autoanalyzed
(count)
The number of times this table has been analyzed by the autovacuum daemon.
postgresql.index_rows_read
(gauge)
The number of index entries returned by scans on this index.
Shown as row
postgresql.table_size
(gauge)
The disk space used by the specified table with TOAST data. Free space map and visibility map are not included.
Shown as byte
postgresql.relation_size
(gauge)
The disk space used by the specified table. TOAST data, indexes, free space map and visibility map are not included.
Shown as byte
postgresql.index_size
(gauge)
The total disk space used by indexes attached to the specified table.
Shown as byte
postgresql.toast_size
(gauge)
The total disk space used by the toast table attached to the specified table.
Shown as byte
postgresql.total_size
(gauge)
The total disk space used by the table, including indexes and TOAST data.
Shown as byte
postgresql.individual_index_size
(gauge)
The disk space used by a specified index.
Shown as byte
postgresql.table.count
(gauge)
The number of user tables in this database.
Shown as table
postgresql.max_connections
(gauge)
The maximum number of client connections allowed to this database.
Shown as connection
postgresql.percent_usage_connections
(gauge)
The number of connections to this database as a fraction of the maximum number of allowed connections.
Shown as fraction
postgresql.replication_delay
(gauge)
The current replication delay in seconds. Only available with postgresql 9.1 and newer
Shown as second
postgresql.replication_delay_bytes
(gauge)
The current replication delay in bytes. Only available with postgresql 9.2 and newer
Shown as byte
postgresql.replication.wal_write_lag
(gauge)
Time elapsed between flushing recent WAL locally and receiving notification that this standby server has written it (but not yet flushed it or applied it). This can be used to gauge the delay that synchronouscommit level remotewrite incurred while committing if this server was configured as a synchronous standby. Only available with postgresql 10 and newer.
Shown as second
postgresql.replication.wal_flush_lag
(gauge)
Time elapsed between flushing recent WAL locally and receiving notification that this standby server has written and flushed it (but not yet applied it). This can be used to gauge the delay that synchronous_commit level on incurred while committing if this server was configured as a synchronous standby. Only available with postgresql 10 and newer.
Shown as second
postgresql.replication.wal_replay_lag
(gauge)
Time elapsed between flushing recent WAL locally and receiving notification that this standby server has written, flushed and applied it. This can be used to gauge the delay that synchronouscommit level remoteapply incurred while committing if this server was configured as a synchronous standby. Only available with postgresql 10 and newer.
Shown as second
postgresql.replication.backend_xmin_age
(gauge)
The age of the standby server's xmin horizon (relative to latest stable xid) reported by hotstandbyfeedback.
postgresql.heap_blocks_read
(gauge)
The number of disk blocks read from this table.
Shown as block
postgresql.heap_blocks_hit
(gauge)
The number of buffer hits in this table.
Shown as hit
postgresql.index_blocks_read
(gauge)
The number of disk blocks read from all indexes on this table.
Shown as block
postgresql.index_blocks_hit
(gauge)
The number of buffer hits in all indexes on this table.
Shown as hit
postgresql.table_bloat
(gauge)
The estimated percentage of table bloat.
Shown as percent
postgresql.index_bloat
(gauge)
The estimated percentage of index bloat.
Shown as percent
postgresql.toast_blocks_read
(gauge)
The number of disk blocks read from this table's TOAST table.
Shown as block
postgresql.toast_blocks_hit
(gauge)
The number of buffer hits in this table's TOAST table.
Shown as hit
postgresql.toast_index_blocks_read
(gauge)
The number of disk blocks read from this table's TOAST table index.
Shown as block
postgresql.toast_index_blocks_hit
(gauge)
The number of buffer hits in this table's TOAST table index.
Shown as block
postgresql.transactions.open
(gauge)
The number of open transactions in this database.
Shown as transaction
postgresql.transactions.idle_in_transaction
(gauge)
The number of 'idle in transaction' transactions in this database.
Shown as transaction
postgresql.snapshot.xmin
(gauge)
Report the lowest transaction ID still active based on pgsnapshotxmin(pgcurrentsnapshot()). All transaction IDs less than xmin are either committed and visible, or rolled back and dead.
postgresql.snapshot.xmax
(gauge)
Report the next transaction ID that will be assigned based on pgsnapshotxmax(pgcurrentsnapshot()).
postgresql.snapshot.xip_count
(gauge)
Report the number of active transactions based on pgsnapshotxip(pgcurrentsnapshot()).
postgresql.before_xid_wraparound
(gauge)
The number of transactions that can occur until a transaction wraparound.
Shown as transaction
postgresql.activity.backend_xmin_age
(gauge)
The age of the oldest backend's xmin horizon relative to latest stable xid.
Shown as transaction
postgresql.activity.backend_xid_age
(gauge)
The age of the oldest backend's xid relative to latest stable xid.
Shown as transaction
postgresql.activity.xact_start_age
(gauge)
The age of the oldest active transactions.
Shown as second
postgresql.active_queries
(gauge)
The number of active queries in this database.
postgresql.active_waiting_queries
(gauge)
The number of waiting queries in this database in state active.
postgresql.waiting_queries
(gauge)
The number of waiting queries in this database.
postgresql.queries.count
(count)
The total query execution count per query_signature, db, and user. (DBM only)
Shown as query
postgresql.queries.time
(count)
The total query execution time per query_signature, db, and user. (DBM only)
Shown as nanosecond
postgresql.queries.rows
(count)
The total number of rows retrieved or affected per query_signature, db, and user. (DBM only)
Shown as row
postgresql.queries.shared_blks_hit
(count)
Total number of shared block cache hits per query_signature, db, and user. (DBM only)
Shown as block
postgresql.queries.shared_blks_read
(count)
Total number of shared blocks read per query_signature, db, and user. (DBM only)
Shown as block
postgresql.queries.shared_blks_dirtied
(count)
Total number of shared blocks dirtied per query_signature, db, and user. (DBM only)
Shown as block
postgresql.queries.shared_blks_written
(count)
Total number of shared blocks written per query_signature, db, and user. (DBM only)
Shown as block
postgresql.queries.local_blks_hit
(count)
Total number of local block cache hits per query_signature, db, and user. (DBM only)
Shown as block
postgresql.queries.local_blks_read
(count)
Total number of local blocks read per query_signature, db, and user. (DBM only)
Shown as block
postgresql.queries.local_blks_dirtied
(count)
Total number of local blocks dirtied per query_signature, db, and user. (DBM only)
Shown as block
postgresql.queries.local_blks_written
(count)
Total number of local blocks written per query_signature, db, and user. (DBM only)
Shown as block
postgresql.queries.temp_blks_read
(count)
Total number of temp blocks read per query_signature, db, and user. (DBM only)
Shown as block
postgresql.queries.temp_blks_written
(count)
Total number of temp blocks written per query_signature, db, and user. (DBM only)
Shown as block
postgresql.queries.blk_read_time
(count)
Total time spent reading blocks per query_signature, db, and user. (DBM only)
Shown as nanosecond
postgresql.queries.blk_write_time
(count)
Total time spent writing blocks per query_signature, db, and user. (DBM only)
Shown as nanosecond
postgresql.queries.duration.max
(gauge)
The age of the longest running query per user, db and app. (DBM only)
Shown as nanosecond
postgresql.queries.duration.sum
(gauge)
The sum of the age of all running queries per user, db and app. (DBM only)
Shown as nanosecond
postgresql.sessions.session_time
(count)
Time spent by database sessions in this database, in milliseconds (note that statistics are only updated when the state of a session changes, so if sessions have been idle for a long time, this idle time won't be included).
Shown as millisecond
postgresql.sessions.active_time
(count)
Time spent executing SQL statements in this database, in milliseconds (this corresponds to the states active and fastpath function call in pgstatactivity).
Shown as millisecond
postgresql.sessions.idle_in_transaction_time
(count)
Time spent idling while in a transaction in this database, in milliseconds (this corresponds to the states idle in transaction and idle in transaction (aborted) in pgstatactivity).
Shown as millisecond
postgresql.sessions.count
(count)
Total number of sessions established to this database.
Shown as session
postgresql.sessions.abandoned
(count)
Number of database sessions to this database that were terminated because connection to the client was lost.
Shown as session
postgresql.sessions.fatal
(count)
Number of database sessions to this database that were terminated by fatal errors.
Shown as session
postgresql.sessions.killed
(count)
Number of database sessions to this database that were terminated by operator intervention.
Shown as session
postgresql.wal.records
(count)
Total number of WAL records generated.
Shown as record
postgresql.wal.full_page_images
(count)
Total number of WAL full page images generated. Full page write will happen when a block is modified for the first time after a checkpoint.
Shown as page
postgresql.wal.bytes
(count)
Total amount of WAL generated in bytes.
Shown as byte
postgresql.wal.buffers_full
(count)
Number of times WAL data was written to disk because WAL buffers became full. WAL changes are stored in WAL buffers first. If the buffer is full, WAL insertions will be blocked until buffer is flushed. The size of this buffer is set by walbuffers configuration. By default, it will use 3% of the sharedbuffers value.
postgresql.wal.write
(count)
Number of times WAL buffers were written out to disk.
Shown as write
postgresql.wal.sync
(count)
Number of times WAL files were synced to disk.
postgresql.wal.write_time
(count)
Total amount of time spent writing WAL buffers to disk, in milliseconds (if trackwalio_timing is enabled, otherwise zero).
Shown as millisecond
postgresql.wal.sync_time
(count)
Total amount of time spent syncing WAL files to disk, in milliseconds (if trackwaliotiming is enabled, fsync is on, and walsyncmethod is either fdatasync, fsync or fsyncwritethrough, otherwise zero).
Shown as millisecond
postgresql.slru.blks_zeroed
(count)
Number of blocks zeroed during initializations of SLRU (simple least-recently-used) cache. SLRU caches are created with a fixed number of pages. For Subtrans, Xact and CommitTs caches, the global transactionId is used to get the page number. Thus, it will increase with the transaction throughput.
Shown as block
postgresql.slru.blks_hit
(count)
Number of times disk blocks were found already in the SLRU (simple least-recently-used), so that a read was not necessary (this only includes hits in the SLRU, not the operating system's file system cache).
Shown as block
postgresql.slru.blks_read
(count)
Number of disk blocks read for this SLRU (simple least-recently-used) cache. SLRU caches are created with a fixed number of pages. When all pages are used, the least recently used block is dumped on disk to create space. Access to the evicted block will require data to be read from the disk first and loaded back in an SLRU cache page, increasing the block read count.
Shown as block
postgresql.slru.blks_written
(count)
Number of disk blocks written for this SLRU (simple least-recently-used) cache. SLRU caches are created with a fixed number of pages. When all pages are used, the least recently used block is dumped on disk to create space. A block eviction doesn't necessarily generate disk write as the block could have been written in a previous eviction.
Shown as block
postgresql.slru.blks_exists
(count)
Number of blocks checked for existence for this SLRU (simple least-recently-used) cache. Only CommitTs and MultiXactOffset caches are checking if blocks are already present on disk.
Shown as block
postgresql.slru.flushes
(count)
Number of flush of dirty data for this SLRU (simple least-recently-used) cache. CommitTs, MultiXact, Subtrans, Xact caches flush will happen during checkpoint. MultiXact cache flush may happen during vacuum.
postgresql.slru.truncates
(count)
Number of truncates for this SLRU (simple least-recently-used) cache. For CommitTs, Xact and MultiXact, truncates will happen when the frozenID progresses. For Subtrans, a truncate can occur during restartpoint and a checkpoint.
postgresql.transactions.duration.max
(gauge)
The age of the longest running transaction per user, db and app. (DBM only)
Shown as nanosecond
postgresql.transactions.duration.sum
(gauge)
The sum of the age of all running transactions per user, db and app. (DBM only)
Shown as nanosecond
postgresql.uptime
(gauge)
The uptime of the server in seconds.
Shown as second
postgresql.wal_size
(gauge)
The sum of all WAL files on disk.
Shown as byte
postgresql.wal_count
(gauge)
The number WAL files on disk.
postgresql.wal_age
(gauge)
The age in seconds of the oldest WAL file.
Shown as second
postgresql.wal_receiver.connected
(gauge)
The status of the WAL receiver. This metric will be set to 1 with a 'status:disconnected' tag if the instance doesn't have a running WAL receiver. Otherwise it will use status value from pgstatwal_receiver.
postgresql.wal_receiver.received_timeline
(gauge)
Timeline number of last write-ahead log location received and flushed to disk, the initial value of this field being the timeline number of the first log location used when WAL receiver is started.
postgresql.wal_receiver.last_msg_send_age
(gauge)
The age of the latest message's send time received from the WAL sender.
Shown as second
postgresql.wal_receiver.last_msg_receipt_age
(gauge)
Time since the reception of the last message from the WAL sender.
Shown as second
postgresql.wal_receiver.latest_end_age
(gauge)
Time since the reception of the last message from the WAL sender with an WAL location update.
Shown as second
postgresql.function.calls
(rate)
The number of calls made to a function.
postgresql.replication_slot.xmin_age
(gauge)
The age of the oldest transaction that this slot needs the database to retain. Only physical replication slot will have a xmin. Orphaned replication slot (no consumer or consumer is not connected) will prevent the xmin horizon from progressing.
Shown as transaction
postgresql.replication_slot.restart_delay_bytes
(gauge)
The amount of WAL bytes that the consumer of this slot may require and won't be automatically removed during checkpoints unless it exceeds maxslotwalkeepsize parameter. Nothing is reported if there's no WAL reservation for this slot.
Shown as byte
postgresql.replication_slot.confirmed_flush_delay_bytes
(gauge)
The delay in bytes between the current WAL position and last position this slot's consumer confirmed. This is only available for logical replication slots
Shown as byte
postgresql.pg_stat_statements.dealloc
(count)
The number of times pgstatstatements had to evict least executed queries because pgstatstatements.max was reached.
postgresql.control.timeline_id
(gauge)
The current timeline id.
postgresql.control.checkpoint_delay
(gauge)
The time since the last checkpoint.
Shown as second
postgresql.relation.pages
(gauge)
Size of a table in pages (1 page == 8KB by default). This is only an estimation used by the planner and is updated by VACUUM or ANALYZE.
postgresql.relation.tuples
(gauge)
Number of live rows in the table. This is only an estimation used by the planner and is updated by VACUUM or ANALYZE. If the table has never been vacuumed or analyze, -1 will be reported.
postgresql.relation.all_visible
(gauge)
Number of pages that are marked as all visible in the table's visibility map. This is only an estimation used by the planner and is updated by VACUUM or ANALYZE.

Agent のバージョン 7.32.0 以降では、Database Monitoring を有効にすると、postgresql.connections メトリクスに stateappdb および user がタグ付けされます。

イベント

PostgreSQL チェックには、イベントは含まれません。

サービスのチェック

postgres.can_connect
Agent が監視対象の PostgreSQL インスタンスに接続できない場合は、CRITICAL を返します。それ以外の場合は、OK を返します。
Statuses: ok, クリティカル

トラブルシューティング

ご不明な点は、Datadog のサポートチームまでお問合せください。

その他の参考資料

お役に立つドキュメント、リンクや記事:

よくあるご質問

ブログ記事