追加のテーブルをクエリする必要があるデータ収集またはカスタムメトリクスの場合は、それらのテーブルの SELECT 権限を datadog ユーザーに付与する必要があるかもしれません。例: grant SELECT on <TABLE_NAME> to datadog; 詳細は PostgreSQL カスタムメトリクスの収集を参照してください。
Store your password using secret management software such as Vault. You can then reference this password as ENC[<SECRET_NAME>] in your Agent configuration files: for example, ENC[datadog_user_database_password]. See Secrets Management for more information.
The examples on this page use datadog_user_database_password to refer to the name of the secret where your password is stored. It is possible to reference your password in plain text, but this is not recommended.
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'
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
logs:- type:filepath:"<LOG_FILE_PATH>"source:postgresqlservice:"<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 を参照してください。
It is common to configure a single Agent host to connect to multiple remote database instances (see Agent installation architectures for DBM). To connect to multiple hosts, create an entry for each host in the Postgres integration config.
In these cases, Datadog recommends limiting the number of instances per Agent to a maximum of 10 database instances to guarantee reliable performance.
Use the database_autodiscovery option to permit the Agent to discover all databases on your host to monitor. You can specify include or exclude fields to narrow the scope of databases discovered. See the sample postgres.d/conf.yaml for more details.
init_config:instances:- dbm:truehost:example-service-primary.example-host.comport:5432username:datadogpassword:'ENC[datadog_user_database_password]'database_autodiscovery:enabled:true# Optionally, set the include field to specify# a set of databases you are interested in discoveringinclude:- mydb.*- example.*tags:- 'env:prod'- 'team:team-discovery'- 'service:example-service'
In order to collect relation metrics (such as postgresql.seq_scans, postgresql.dead_rows, postgresql.index_rows_read, and postgresql.table_size), the Agent must be configured to connect to each database (by default, the Agent only connects to the postgres database).
Specify a single “DBM” instance to collect DBM telemetry from all databases. Use the database_autodiscovery option to avoid specifying each database name.
init_config:instances:# This instance is the "DBM" instance. It will connect to the# all logical databases, and send DBM telemetry from all databases- dbm:truehost:example-service-primary.example-host.comport:5432username:datadogpassword:'ENC[datadog_user_database_password]'database_autodiscovery:enabled:trueexclude:- ^users$- ^inventory$relations:- relation_regex:.*# This instance only collects data from the `users` database# and collects relation metrics from tables prefixed by "2022_"- host:example-service-primary.example-host.comport:5432username:datadogpassword:'ENC[datadog_user_database_password]'dbname:usersdbstrict:truerelations:- relation_regex:2022_.*relkind:- r- i# This instance only collects data from the `inventory` database# and collects relation metrics only from the specified tables- host:example-service-primary.example-host.comport:5432username:datadogpassword:'ENC[datadog_user_database_password]'dbname:inventorydbstrict:truerelations:- relation_name:products- relation_name:external_seller_products
Use the database_autodiscovery option to avoid specifying each logical database. See the sample postgres.d/conf.yaml for more details.
init_config:# This instance only collects data from the `users` database# and collects relation metrics only from the specified tablesinstances:- dbm:truehost:example-service-primary.example-host.comport:5432username:datadogpassword:'ENC[datadog_user_database_password]'dbname:usersdbstrict:truecollect_schemas:enabled:truerelations:- products- external_seller_products# This instance detects every logical database automatically# and collects relation metrics from every table- dbm:truehost:example-service–replica-1.example-host.comport:5432username:datadogpassword:'ENC[datadog_user_database_password]'database_autodiscovery:enabled:truecollect_schemas:enabled:truerelations:- relation_regex:.*
If the Agent must connect through a proxy such as the Cloud SQL Auth proxy, all telemetry is tagged with the hostname of the proxy rather than the database instance. Use the reported_hostname option to set a custom override of the hostname detected by the Agent.