Set up PostgreSQL monitoring using the NRDOT Collector for Azure Database for PostgreSQL flexible server instances. Azure flexible server environments have specific considerations for extensions and server parameters.
Prerequisites
Before you install, make sure you have:
- PostgreSQL
14and above - A New Relic license key.
- Network connectivity between the host where you install the NRDOT Collector and your Azure Database for PostgreSQL flexible server instance.
- Network connectivity to New Relic OTLP endpoints documentation
- Azure flexible server admin login credentials.
For supported PostgreSQL versions, required grants, and recommended server parameters, see Compatibility and prerequisites.
Set up NRDOT Collector
Install the NRDOT Collector on a system that can connect to your Azure Database for PostgreSQL flexible server instance:
Configure database user and grants
Create a monitoring user with the necessary privileges for your Azure Database for PostgreSQL flexible server instance.
To create the monitoring user and grants:
Connect to your Azure Database for PostgreSQL flexible server instance as the admin login:
bash$psql --host=<YOUR_AZURE_ENDPOINT> --dbname=postgres --port=5432 --username=<YOUR_ADMIN_USERNAME>Create the monitoring user:
CREATE USER <YOUR_DB_USERNAME> WITH LOGIN PASSWORD '<YOUR_DB_PASSWORD>';Grant the monitoring user role membership as needed:
If you're on PostgreSQL 15 and above, assign role to inherit privileges:
ALTER ROLE <YOUR_DB_USERNAME> INHERIT;Tip
If you're on PostgreSQL 14, the monitoring user inherits privileges by default, so you can skip this step.
Create the following schema and grants in every database you want to monitor:
CREATE SCHEMA IF NOT EXISTS otel;GRANT USAGE ON SCHEMA otel TO <YOUR_DB_USERNAME>;GRANT USAGE ON SCHEMA public TO <YOUR_DB_USERNAME>;GRANT SELECT ON ALL TABLES IN SCHEMA public TO <YOUR_DB_USERNAME>;GRANT pg_monitor TO <YOUR_DB_USERNAME>;CREATE EXTENSION IF NOT EXISTS pg_stat_statements;(Optional) To collect vector metrics, create the
pgvectorextension in each database:CREATE EXTENSION IF NOT EXISTS vector;The
l1,hamming, andjaccarddistance functions requirepgvectorversion0.7.0or above.(Optional) To verify the connection and grants, run:
bash$psql --username=<YOUR_DB_USERNAME> --host=<YOUR_AZURE_ENDPOINT> --port=5432 --dbname=<YOUR_DATABASE_NAME> --command '\conninfo'$psql --username=<YOUR_DB_USERNAME> --host=<YOUR_AZURE_ENDPOINT> --port=5432 --dbname=<YOUR_DATABASE_NAME> \>-c "SELECT * FROM pg_stat_database LIMIT 1;" && echo "pg_stat_database OK">psql --username=<YOUR_DB_USERNAME> --host=<YOUR_AZURE_ENDPOINT> --port=5432 --dbname=<YOUR_DATABASE_NAME> \>-c "SELECT * FROM pg_stat_activity LIMIT 1;" && echo "pg_stat_activity OK">psql --username=<YOUR_DB_USERNAME> --host=<YOUR_AZURE_ENDPOINT> --port=5432 --dbname=<YOUR_DATABASE_NAME> \>-c "SELECT * FROM pg_stat_statements LIMIT 1;" && echo "pg_stat_statements OK"If each command completes without an error, the monitoring user, host, and port are all correct.
Configure NRDOT Collector
Configure the NRDOT Collector with your Azure Database for PostgreSQL flexible server-specific settings.
This configuration focuses on essential PostgreSQL monitoring with the nrpostgresql receiver only.
full configuration
This baseline configuration captures essential metrics. To see the complete metric catalog, refer to the configuration reference.
Create a configuration file named as
postgresql-config.yaml:bash$sudo nano /etc/nrdot-collector/postgresql-config.yamlAdd the following configuration to the
postgresql-config.yamlfile you created in the previous step.
1receivers:2 nrpostgresql:3 endpoint: "myserver.postgres.database.azure.com:5432"4 username: "newrelic"5 password: "YOUR_PASSWORD"6 databases:7 - YOUR_DATABASE_NAME8 collection_interval: 15s9 events:10 db.server.top_query:11 enabled: true12 db.server.query_sample:13 enabled: true14 db.server.query_plan:15 enabled: true16 top_query_collection:17 max_rows_per_query: 100018 top_n_query: 20019 collection_interval: 60s20 allowed_comment_keys: [nr_service_guid]21 query_sample_collection:22 max_rows_per_query: 100023 allowed_comment_keys: [nr_service_guid]24 resource_attributes:25 db.system.version:26 enabled: true27 # Metrics needed for the out-of-the-box dashboard but disabled by default:28 # see "Available metrics" below for the full default-on/default-off breakdown.29 metrics:30 postgresql.database.locks:31 enabled: true32 postgresql.deadlocks:33 enabled: true34 postgresql.function.calls:35 enabled: true36 postgresql.query.conflicts:37 enabled: true38 postgresql.sequential_scans:39 enabled: true40 postgresql.temp.io:41 enabled: true42 postgresql.temp_files:43 enabled: true44 # Azure Database for PostgreSQL flexible server enforces TLS by default (require_secure_transport).45 tls:46 insecure: false47 ca_file: <PATH_TO_AZURE_CA_CERTIFICATE>48processors:49 batch:50 batch/metrics:51 send_batch_size: 819252 send_batch_max_size: 819253 timeout: 10s54exporters:55 otlp/newrelic:56 endpoint: "https://otlp.nr-data.net:4318"57 headers:58 api-key: "YOUR_LICENSE_KEY"59 compression: gzip60 sending_queue:61 enabled: true62 sizer: bytes63 queue_size: 100_000_00064 num_consumers: 1065 batch:66 sizer: bytes67 max_size: 1_000_00068 min_size: 069 flush_timeout: 5s70 retry_on_failure:71 enabled: true72 initial_interval: 5s73 max_interval: 30s74 max_elapsed_time: 300s75service:76 telemetry:77 metrics:78 level: none79 pipelines:80 metrics:81 receivers: [nrpostgresql]82 processors: [batch/metrics]83 exporters: [otlp/newrelic]84 logs:85 receivers: [nrpostgresql]86 processors: [batch]87 exporters: [otlp/newrelic]Tip
You can also:
- Configure multiple receivers: To monitor multiple PostgreSQL instances from one collector.
- Link your PostgreSQL database with APM: To correlate your application performance with database operations. This allows you to see exactly which applications are generating specific database workloads.
- Query plans for write statements: To collect query plans for locking or write statements without granting write access to the monitoring user.
- Set up secret management: To securely manage sensitive information, such as database credentials. This helps to enhance the security of your monitoring setup by avoiding hardcoding sensitive data in configuration files.
Validate NRDOT Collector configuration
Update the config path to point to your new
postgresql-config.yamlfile:bash$sudo sed -i 's|OTELCOL_OPTIONS="--config=/etc/nrdot-collector/config.yaml"|OTELCOL_OPTIONS="--config=/etc/nrdot-collector/postgresql-config.yaml"|' /etc/nrdot-collector/nrdot-collector.confValidate the NRDOT Collector configuration to ensure it's correctly formatted and will work properly:
bash$sudo /usr/bin/nrdot-collector validate --config=/etc/nrdot-collector/postgresql-config.yaml
Restart NRDOT Collector
After configuring the collector, restart the NRDOT Collector service to apply the changes:
$sudo systemctl restart nrdot-collectorTo verify that the collector is running properly, check the service status:
$sudo systemctl status nrdot-collectorTip
Always restart the NRDOT Collector after making configuration changes to ensure the new settings take effect.
Find and use your data
Query samples and top queries arrive as log events (event.name = 'db.server.query_sample' / 'db.server.top_query', db.system.name = 'postgresql'). Metrics arrive under the postgresql.* namespace.
To find your Azure Database for PostgreSQL flexible server entity in New Relic:
- Go to https://one.newrelic.com > All Capabilities > Databases.
- From the Entity type dropdown, select PostgreSQL instance, then click Apply.
- Select your Azure Database for PostgreSQL flexible server instance from the list of entities.
Azure Database for PostgreSQL flexible server behavior
When you monitor an Azure Database for PostgreSQL flexible server instance, behaviors differ from self-managed PostgreSQL or Amazon RDS due to Azure platform architecture rather than the receiver. All standard PostgreSQL metrics remain available on Azure.
Azure preloads
pg_stat_statements(populatespostgresql.query.execution.time) andpgvector(populatespostgresql.vector.*) extensions on the server, but you must add them to theazure.extensionsserver parameter beforeCREATE EXTENSIONsucceeds. For configuration steps, see Configure database user and grants.Replication metrics (
postgresql.replication.data_delay,postgresql.wal.lag, andpostgresql.wal.delay) populate from either an explicit read replica or Azure's built-in high availability (HA) standby, distinguished bysync_state(asyncorsync). Additionally,postgresql.wal.delayrequires thepostgresqlreceiver.preciselagmetricsfeature gate, which the baseline configuration on this page doesn't enable.track_functionsdefaults tonone(standard PostgreSQL behavior, not specific to Azure). Set it toplorallto enablepostgresql.function.calls.
Related documentation
Instrumentation in self-hosted environments
Learn how to set up PostgreSQL monitoring in self-hosted environments with New Relic.
Metrics reference
Learn about the available metrics collected by the NRDOT Collector.
Troubleshooting guide
Learn how to troubleshoot common issues with PostgreSQL monitoring.