Cette page n'est pas encore disponible en français, sa traduction est en cours. Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.
Database Monitoring provides deep visibility into your Postgres databases by exposing query metrics, query samples, explain plans, database states, failovers, and events.
The Agent collects telemetry directly from the database by logging in as a read-only user. Do the following setup to enable Database Monitoring with your Postgres database:
RDS Quick Install is our recommended installation method for smaller environments (for example 20 database hosts) or those new to DBM and want to try it out quickly. For those managing large fleets of databases where deploying the agent via UI doesn't scale as well we recommend the standard installation, to manually manage the agent yourself or integrate with your automation practices.
The default Agent configuration for Database Monitoring is conservative, but you can adjust settings such as the collection interval and query sampling rate to better suit your needs. For most workloads, the Agent represents less than one percent of query execution time on the database and less than one percent of CPU.
Database Monitoring runs as an integration on top of the base Agent (see benchmarks).
Proxies, load balancers, and connection poolers
The Datadog Agent must connect directly to the host being monitored. For self-hosted databases, 127.0.0.1 or the socket is preferred. The Agent should not connect to the database through a proxy, load balancer, or connection pooler such as pgbouncer. If the Agent connects to different hosts while it is running (as in the case of failover, load balancing, and so on), the Agent calculates the difference in statistics between two hosts, producing inaccurate metrics.
Data security considerations
See Sensitive information for information about what data the Agent collects from your databases and how to ensure it is secure.
Required for postgresql.queries.* metrics. Enables collection of query metrics using the pg_stat_statements extension.
track_activity_query_size
4096
Required for collection of larger queries. Increases the size of SQL text in pg_stat_activity. If left at the default value then queries longer than 1024 characters will not be collected.
pg_stat_statements.track
ALL
Optional. Enables tracking of statements within stored procedures and functions.
pg_stat_statements.max
10000
Optional. Increases the number of normalized queries tracked in pg_stat_statements. This setting is recommended for high-volume databases that see many different types of queries from many different clients.
pg_stat_statements.track_utility
off
Optional. Disables utility commands like PREPARE and EXPLAIN. Setting this value to off means only queries like SELECT, UPDATE, and DELETE are tracked.
track_io_timing
on
Optional. Enables collection of block read and write times for queries.
The Datadog Agent requires read-only access to the database server in order to collect statistics and queries.
The following SQL commands should be executed on the primary database server (the writer) in the cluster if Postgres is replicated. Choose a PostgreSQL database on the server for the Agent to connect to. The Agent can collect telemetry from all databases on the database server regardless of which one it connects to, so a good option is to use the default postgres database. Choose a different database only if you need the Agent to run custom queries against data unique to that database.
Connect to the chosen database as a superuser (or another user with sufficient permissions). For example, if your chosen database is postgres, connect as the postgres user using psql by running:
psql -h mydb.example.com -d postgres -U postgres
Create the datadog user:
CREATEUSERdatadogWITHpassword'<PASSWORD>';
Note: IAM authentication is also supported. Please see the guide on how to configure this for your RDS instance.
For data collection or custom metrics that require querying additional tables, you may need to grant the SELECT permission on those tables to the datadog user. Example: grant SELECT on <TABLE_NAME> to datadog;. See PostgreSQL custom metric collection for more information.
Create the function in every database to enable the Agent to collect explain plans.
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.
To verify the permissions are correct, run the following commands to confirm the Agent user is able to connect to the database and read the core tables:
To monitor RDS hosts, install the Datadog Agent in your infrastructure and configure it to connect to each instance endpoint remotely. The Agent does not need to run on the database, it only needs to connect to it. For additional Agent installation methods not mentioned here, see the Agent installation instructions.
To configure collecting Database Monitoring metrics for an Agent running on a host, for example when you provision a small EC2 instance for the Agent to collect from an RDS database:
Edit the postgres.d/conf.yaml file to point to your host / port and set the masters to monitor. See the sample postgres.d/conf.yaml for all available configuration options.
init_config:instances:- dbm:truehost:'<AWS_INSTANCE_ENDPOINT>'port:5432username:datadogpassword:'ENC[datadog_user_database_password]'tags:- "dbinstanceidentifier:<DB_INSTANCE_NAME>"## Required for Postgres 9.6: Uncomment these lines to use the functions created in the setup# pg_stat_statements_view: datadog.pg_stat_statements()# pg_stat_activity_view: datadog.pg_stat_activity()## Optional: Connect to a different database if needed for `custom_queries`# dbname: '<DB_NAME>'
For Agent versions ≤ 7.49, add the following setting to the instance config where host and port are specified:
ssl:allow
If you want to authenticate with IAM, specify the region and instance_endpoint parameters, and set managed_authentication.enabled to true.
Note: only enable managed_authentication if you want to use IAM authentication. IAM authentication takes precedence over the password field.
init_config:instances:- dbm:truehost:'<AWS_INSTANCE_ENDPOINT>'port:5432username:datadogaws:instance_endpoint:'<AWS_INSTANCE_ENDPOINT>'region:'<REGION>'managed_authentication:enabled:truetags:- "dbinstanceidentifier:<DB_INSTANCE_NAME>"## Required for Postgres 9.6: Uncomment these lines to use the functions created in the setup# pg_stat_statements_view: datadog.pg_stat_statements()# pg_stat_activity_view: datadog.pg_stat_activity()## Optional: Connect to a different database if needed for `custom_queries`# dbname: '<DB_NAME>'
To configure the Database Monitoring Agent running in a Docker container such as in ECS or Fargate, you can set the Autodiscovery Integration Templates as Docker labels on your agent container.
Note: The Agent must have read permission on the Docker socket for Autodiscovery of labels to work.
Get up and running quickly by executing the following command to run the agent from your command line. Replace the values to match your account and environment:
If you have a Kubernetes cluster, use the Datadog Cluster Agent for Database Monitoring.
Follow the instructions to enable the cluster checks if not already enabled in your Kubernetes cluster. You can declare the Postgres configuration either with static files mounted in the Cluster Agent container or using service annotations:
Complete the following steps to install the Datadog Cluster Agent on your Kubernetes cluster. Replace the values to match your account and environment.
To configure a cluster check with a mounted configuration file, mount the configuration file in the Cluster Agent container on the path: /conf.d/postgres.yaml:
cluster_check:true# Make sure to include this flaginit_config:instances:- dbm:truehost:'<AWS_INSTANCE_ENDPOINT>'port:5432username:datadogpassword:'ENC[datadog_user_database_password]'tags:- dbinstanceidentifier:<DB_INSTANCE_NAME>## Required: For Postgres 9.6, uncomment these lines to use the functions created in the setup# pg_stat_statements_view: datadog.pg_stat_statements()# pg_stat_activity_view: datadog.pg_stat_activity()
Rather than mounting a file, you can declare the instance configuration as a Kubernetes Service. To configure this check for an Agent running on Kubernetes, create a Service in the same namespace as the Datadog Cluster Agent:
The Cluster Agent automatically registers this configuration and begin running the Postgres check.
To avoid exposing the datadog user’s password in plain text, use the Agent’s secret management package and declare the password using the ENC[] syntax.
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.