데이터베이스 모니터링에 대한 기본 Agent 설정은 변경하지 않는 것이 좋으나 수집 간격 및 쿼리 샘플링 속도와 같은 설정은 필요에 맞게 조정할 수 있습니다. 대부분의 워크로드에서 Agent는 데이터베이스에서 쿼리 실행 시간의 1% 미만, CPU의 1% 미만을 나타냅니다.
Datadog Agent는 모니터링 중인 호스트에 직접 연결해야 합니다. 자체 호스팅 데이터베이스의 경우 127.0.0.1 또는 소켓이 선호됩니다. Agent는 pgbouncer와 같은 프록시, 로드 밸런서, 연결 풀러를 통해 데이터베이스에 연결해서는 안됩니다. Agent가 실행되는 동안 다른 호스트에 연결하는 경우(페일오버, 로드밸런싱 등) Agent는 두 호스트 간의 통계 차이를 계산하여 부정확한 메트릭을 생성합니다.
데이터 보안 고려 사항
Agent가 데이터베이스에서 수집하는 데이터와 데이터 보안을 유지하는 방법에 대한 자세한 내용은 민감한 정보를 참조하세요.
더 큰 쿼리를 수집하는 데 필요합니다. pg_stat_activity에서 SQL 텍스트의 크기를 늘립니다. 기본값으로 두면 1024자보다 긴 쿼리는 수집되지 않습니다.
pg_stat_statements.track
ALL
선택 사항. 저장 프로시저 및 함수 내에서 명령문을 추적할 수 있습니다.
pg_stat_statements.max
10000
선택 사항. pg_stat_statements에서 추적되는 정규화된 쿼리 수를 늘립니다. 이 설정은 다양한 클라이언트의 다양한 유형의 쿼리를 보는 대용량 데이터베이스에 권장됩니다.
pg_stat_statements.track_utility
off
선택 사항. PREPARE 및 EXPLAIN과 같은 유틸리티 명령을 비활성화합니다. 이 값을 off로 설정하면 SELECT, UPDATE, DELETE와 같은 쿼리만 추적됩니다.
track_io_timing
on
선택 사항. 쿼리에 대한 블록 읽기 및 쓰기 시간 수집을 활성화합니다.
파라미터
값
설명
azure.extensions
pg_stat_statements
postgresql.queries.* 메트릭에 필요합니다. pg_stat_statements 확장을 사용하여 쿼리 메트릭 수집을 활성화합니다.
track_activity_query_size
4096
더 큰 쿼리를 수집하는 데 필요합니다. pg_stat_activity에서 SQL 텍스트의 크기를 늘립니다. 기본값으로 두면 1024자보다 긴 쿼리는 수집되지 않습니다.
pg_stat_statements.track
ALL
선택 사항. 저장 프로시저 및 함수 내에서 명령문을 추적할 수 있습니다.
pg_stat_statements.max
10000
선택 사항. pg_stat_statements에서 추적되는 정규화된 쿼리 수를 늘립니다. 이 설정은 다양한 클라이언트의 다양한 유형의 쿼리를 보는 대용량 데이터베이스에 권장됩니다.
pg_stat_statements.track_utility
off
선택 사항. PREPARE 및 EXPLAIN과 같은 유틸리티 명령을 비활성화합니다. 이 값을 off로 설정하면 SELECT, UPDATE, DELETE와 같은 쿼리만 추적됩니다.
track_io_timing
on
선택 사항. 쿼리에 대한 블록 읽기 및 쓰기 시간 수집을 활성화합니다.
에이전트에 접근 권한 부여
Datadog 에이전트가 통계와 쿼리를 수집하려면 데이터베이스에 읽기 전용 액세스가 필요합니다.
Postgres가 복제된 경우 클러스터의 기본 데이터베이스 서버(작성자)에서 다음 SQL 명령을 실행해야 합니다. Agent가 연결할 데이터베이스 서버에서 PostgreSQL 데이터베이스를 선택합니다. Agent는 연결된 데이터베이스에 관계없이 데이터베이스 서버의 모든 데이터베이스에서 원격 측정을 수집할 수 있으므로 기본 postgres 데이터베이스를 사용하는 것이 좋습니다. Agent가 해당 데이터베이스 고유의 데이터에 대한 사용자 지정 쿼리를 실행하는 경우에만 다른 데이터베이스를 선택하세요.
선택한 데이터베이스를 수퍼유저(또는 충분한 권한이 있는 다른 사용자)와 연결합니다. 예를 들어 선택한 데이터베이스가 postgres면 다음을 실행하여 psql을 사용하는 postgres 사용자로 연결합니다.
psql -h mydb.example.com -d postgres -U postgres
datadog 사용자 생성:
CREATEUSERdatadogWITHpassword'<PASSWORD>';
참고: Microsoft Entra ID 관리 ID 인증도 지원됩니다. Azure 인스턴스에 대해 이를 구성하는 방법은 가이드를 참조하세요.
추가 테이블을 쿼리해야 하는 데이터 수집 또는 커스텀 메트릭의 경우 해당 테이블에 대한 SELECT 권한을 datadog 사용자에게 부여해야 할 수도 있습니다. 예: <TABLE_NAME>에서 SELECT 권한을 Datadog에 부여합니다. 자세한 내용은 PostgreSQL 커스텀 메트릭 수집을 참조하세요.
권한이 정확한지 확인하려면 다음 명령을 실행해 에이전트 사용자가 데이터베이스에 연결하고 코어 테이블을 읽을 수 있는지 확인합니다.
psql -h mydb.example.com -U datadog postgres -A \
-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"psql -h mydb.example.com -U datadog postgres -A \
-c "select * from pg_stat_activity limit 1;"\
&&echo -e "\e[0;32mPostgres pg_stat_activity read OK\e[0m"\
||echo -e "\e[0;31mCannot read from pg_stat_activity\e[0m"psql -h mydb.example.com -U datadog postgres -A \
-c "select * from pg_stat_statements limit 1;"\
&&echo -e "\e[0;32mPostgres pg_stat_statements read OK\e[0m"\
||echo -e "\e[0;31mCannot read from pg_stat_statements\e[0m"
psql -h mydb.example.com -U datadog postgres -A \
-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"psql -h mydb.example.com -U datadog postgres -A \
-c "select * from pg_stat_activity limit 1;"\
&&echo -e "\e[0;32mPostgres pg_stat_activity read OK\e[0m"\
||echo -e "\e[0;31mCannot read from pg_stat_activity\e[0m"psql -h mydb.example.com -U datadog postgres -A \
-c "select * from pg_stat_statements limit 1;"\
&&echo -e "\e[0;32mPostgres pg_stat_statements read OK\e[0m"\
||echo -e "\e[0;31mCannot read from pg_stat_statements\e[0m"
암호 입력 메시지가 나타나면 datadog 사용자를 생성할 때 입력한 암호를 사용합니다.
에이전트 설치
Azure Postgres 데이터베이스를 모니터링하려면 인프라스트럭처에 Datadog 에이전트를 설치하고 각 인스턴스에 원격으로 연결하도록 설정합니다. 에이전트를 데이터베이스에서 실행할 필요가 없고 데이터베이스에 연결만 하면 됩니다. 여기에 나와있지 않은 다른 설치 방법을 보려면 에이전트 설치 지침을 참고하세요.
호스트에서 실행하는 데이터베이스 모니터링 메트릭 수집을 설정하려면(예: 에이전트가 Azure 데이터베이스에서 수집할 수 있도록 소규모 가상 머신 인스턴스를 프로비저닝할 때) 다음을 따릅니다.
postgres.d/conf.yaml 파일을 편집해 host/port를 가리키도록 하고, 모니터링할 마스터를 설정합니다. 사용할 수 있는 모든 설정 옵션을 보려면 postgres.d/conf.yaml 샘플을 참고하세요.
init_config:instances:- dbm:truehost:'<AZURE_INSTANCE_ENDPOINT>'port:5432username:'datadog@<AZURE_INSTANCE_ENDPOINT>'password:'<PASSWORD>'ssl:'require'## 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>'# After adding your project and instance, configure the Datadog Azure integration to pull additional cloud data such as CPU, Memory, etc.azure:deployment_type:'<DEPLOYMENT_TYPE>'fully_qualified_domain_name:'<AZURE_INSTANCE_ENDPOINT>'
연결된 설정 파일로 클러스터 점검을 설정하려면 다음 경로로 설정 파일을 클러스터 에이전트 컨테이너에 연결합니다. /conf.d/postgres.yaml:
cluster_check:true# 이 플래그를 반드시 포함하세요init_config:instances:- dbm:truehost:'<AZURE_INSTANCE_ENDPOINT>'port:5432username:'datadog@<AZURE_INSTANCE_ENDPOINT>'password:'<PASSWORD>'ssl:"require"# 프로젝트와 인스턴스를 추가한 후 CPU, 메모리 등과 같은 추가 클라우드 데이터를 가져오도록 Datadog Azure 통합을 구성합니다.azure:deployment_type:'<DEPLOYMENT_TYPE>'fully_qualified_domain_name:'<AZURE_INSTANCE_ENDPOINT>'## 필수: Postgres 9.6의 경우 설정에서 생성된 함수를 사용하려면 이 줄의 주석 처리를 제거하세요.# pg_stat_statements_view: datadog.pg_stat_statements()# pg_stat_activity_view: datadog.pg_stat_activity()
쿠버네티스 서비스 주석으로 설정
파일을 연결하는 대신 쿠버네티스 서비스로 인스턴스 설정을 지정할 수 있습니다. 쿠버네티스가 실행되는 에이전트에서 이 점검을 설정하려면 Datadog 클러스터 에이전트와 동일한 네임스페이스로 서비스를 생성하세요.
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.
Datadog recommends using one Agent to monitor no more than 30 database instances.
Benchmarks show that one Agent running on a t4g.medium EC2 instance (2 CPUs and 4GB of RAM) can successfully monitor 30 RDS db.t3.medium instances (2 CPUs and 4GB of RAM).
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'
Running custom queries
To collect custom metrics, use the custom_queries option. See the sample postgres.d/conf.yaml for more details.
init_config:instances:- dbm:truehost:localhostport:5432username:datadogpassword:'ENC[datadog_user_database_password]'custom_queries:- metric_prefix:employeequery:SELECT age, salary, hours_worked, name FROM hr.employees;columns:- name:custom.employee_agetype:gauge- name:custom.employee_salarytype:gauge- name:custom.employee_hourstype:count- name:nametype:tagtags:- 'table:employees'
Monitoring relation metrics for multiple databases
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:.*
Working with hosts through a proxy
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.