The NRDOT Collector reports a wide range of PostgreSQL metrics. New Relic collects the metrics and query-level events in Default metrics and events automatically. For deeper insight into performance and health, enable any of the metrics listed in Full-feature metrics.
Default metrics and events
팁
Each metric is scoped to a specific database, table, schema, or index. This context is set on the resource, not as a metric attribute.
These metrics are collected automatically and power the New Relic UI, including the out-of-the-box dashboard.
Metric | Description |
|---|---|
| Number of backend connections |
| Number of allocated buffers |
| Number of written buffers. This metric has the following available attribute: |
| Number of checkpoints performed. This metric has the following available attribute: |
| Total time spent on writing and syncing files to disk by checkpoints. This metric has the following available attribute: |
| Number of times the background writer stopped a cleaning scan because it had already written too many buffers |
| Number of blocks read. This metric has the following available attribute: |
| Number of commits |
| Maximum number of client connections allowed |
| Number of user databases |
| Database disk usage |
| Number of index scans on a table |
| Size of the index on disk |
| Number of database row operations. This metric has the following available attribute: |
| Amount of data delayed in replication. This metric has the following available attribute: |
| Number of rollbacks |
| Number of rows in the database. This metric has the following available attribute: |
| Number of user tables in a database |
| Disk space used by a table |
| Number of times a table was manually vacuumed |
| Age of the oldest WAL file. Requires WAL enabled with at least one replica |
| Time between flushing recent WAL locally and receiving notification the standby completed an operation. Requires WAL + at least one replica. This metric has the following available attributes: |
| Number of database locks. Used by the Database Locks by Mode/Type dashboard widget. |
| Number of deadlocks. Used by the Deadlocks dashboard widget. |
| Calls made to a function. Used by the Function Calls/min dashboard widget. Requires |
| Queries canceled due to recovery conflicts. Standby-only; zero on primaries. Used by the Query Conflicts dashboard widget. |
| Number of sequential scans. Used by the Sequential Scans/min dashboard widget. |
| Total data written to temporary files by queries. Used by the Temp Files & Temp I/O (MB/min) dashboard widget. |
| Number of temporary files. Used by the Temp Files & Temp I/O (MB/min) dashboard widget. |
Query events
The following events are collected as OpenTelemetry log records and are enabled by default. They provide query-level telemetry data.
Real-time visibility into currently-running database statements: a point-in-time snapshot taken every scrape, not a complete execution log. This event is enabled by default and requires the monitoring user to hold pg_monitor.
Use the query_sample_collection block to tune its behavior:
query_sample_collection: max_rows_per_query: 1000 allowed_comment_keys: [nr_service_guid]Available parameters
Parameter | Description |
|---|---|
| The maximum number of rows returned from the query against |
| Keys to extract from leading SQL comments for APM-DB correlation |
Attributes collected
Attribute | Description |
|---|---|
| Name of the database. This is always |
| The SQL statement text |
| APM-correlation comment tags. For more information, refer to Link your PostgreSQL database with APM |
| MD5 of normalized SQL for cross-engine correlation |
| User logged into this backend |
| Current overall state of the backend |
| Process ID of this backend |
| UTC (RFC3339) timestamp the backend/connection started. Stable for the connection's lifetime, unlike |
| Whole seconds since backend connection start. |
| Name of the connected application |
| Client IP address / TCP port |
| Reverse-DNS hostname of the client |
| When the currently active (or last) query started |
| Wait event name / category, if the backend is currently waiting |
| Identifier of this backend's most recent query |
| Query duration in delta milliseconds |
| Array of PIDs blocking this session. Empty when not blocked |
| UTC timestamp when the current lock wait began. Empty when not blocked |
| Whole seconds waited for a lock. |
| Lock mode / resource type / relation name being waited on. Empty when not blocked |
| UTC timestamp when the current transaction started. Empty when no active transaction |
Aggregated per-normalized-query execution stats from pg_stat_statements, reported as incremental (delta) values since the last collection cycle. This event is enabled by default and requires the pg_stat_statements extension in every scanned database.
Use the top_query_collection block to tune its behavior:
top_query_collection: max_rows_per_query: 1000 top_n_query: 100 collection_interval: 60s allowed_comment_keys: [nr_service_guid]Available parameters
Parameter | Description |
|---|---|
| The maximum number of rows returned from the query against |
| The maximum number of active queries to report in a single run. The default value is set to |
| The interval at which top queries are collected. If not set, the global |
| The maximum number of EXPLAIN queries sent in each scrape interval, which limits the performance impact on your database. The default value is set to |
| The size of the query plan cache used to store EXPLAIN results. The default value is set to |
| How long a cached query plan stays valid before the receiver re-runs EXPLAIN to refresh it. The default value is set to |
| Keys to extract from leading SQL comments for APM-DB correlation |
Attributes collected
Attribute | Description |
|---|---|
| Name of the database. This is always |
| The SQL statement text (normalized, |
| Same as |
| MD5 of normalized SQL for cross-engine correlation |
| Times executed / rows retrieved-affected, delta values |
| Shared block activity, delta values |
| Temp block activity, delta values |
| Hash identifying identical normalized queries |
| OID of the role that executed the statement. Stays set even after the role is dropped |
| Role that executed the query |
| Total execution / planning time, delta milliseconds |
| The EXPLAIN plan for the statement, if obtainable (see EXPLAIN mechanics below). Not present here if the |
Execution plan collection (EXPLAIN) mechanics
- Rate limiting:
top_query_collection.max_explain_each_interval(default 1000) caps EXPLAINs per scrape. - Caching:
query_plan_cache_size/query_plan_cache_ttl(default 1000 entries / 1h) cache a plan once obtained, keyed by query ID. - PostgreSQL 12+ requirement: parameterized-query EXPLAIN needs
plan_cache_mode = force_generic_planbeforePREPARE/EXPLAIN EXECUTE, only available on PostgreSQL 12+. On older servers the receiver detects the version and skips EXPLAIN for that query rather than sending aSETthat would fail. - Privilege boundary: by default, EXPLAIN runs directly as the monitoring user, and Postgres checks table privileges at plan time, so row-locking or write statements fail with
permission deniedunless granted write access, which the monitoring user should never have. Useexplain_function_name(see Query plans for write statements) to work around this without granting write access. - If a plan can't be obtained for any reason,
postgresql.query_planis simply empty for that row. No error is surfaced.
Execution plan for a query, reported as its own event so the plan can be filtered, routed, or dropped independently of top_query's statistics. This event requires db.server.top_query to also be enabled. This event is enabled by default.
Attribute | Description |
|---|---|
| Name of the database. This is always |
| Hash code identifying the normalized query this plan belongs to |
| Database the query ran against |
| OID of the role that executed the statement. Stays set even after the role is dropped; used to join back to |
| Name of the role that executed the query. Empty if the role has since been dropped |
| The execution plan PostgreSQL used for the query |
Full-feature metrics
The full-feature configuration collects every default metric plus the following additional metrics. These metrics are organized by functionality. You can set any of these metrics to true in the metrics section of your configuration to enable them.
Additional database activity metrics not used by the dashboard:
Metric | Description |
|---|---|
| Disk blocks found already in the buffer cache |
| Disk blocks read in this database |
| Rows fetched by queries in the database |
| Rows returned by queries in the database |
| Rows inserted by queries in the database |
| Rows updated by queries in the database |
| Rows deleted by queries in the database |
| Total execution time of SQL statements tracked by |
Metric | Description |
|---|---|
| Precise replacement for |
Vector similarity search metrics require PostgreSQL 13+ and the pg_stat_statements and pgvector extensions:
Metric | Description |
|---|---|
| Vector similarity search executions, grouped by distance function. This metric has the following available attribute: |
| Cumulative execution time of vector searches. This metric has the following available attribute: |
| Cumulative rows returned by vector searches. This metric has the following available attribute: |
| Vectors inserted into pgvector tables |
| Cumulative execution time of pgvector inserts |
Attribute glossary
The following table describes every attribute referenced in the metric descriptions above. Attributes whose meaning depends on the metric they're attached to (such as source, type, and operation) aren't listed here; their specific values are called out inline next to each metric instead.
Attribute | Description | Values |
|---|---|---|
| The tuple (row) state |
|
| The IP address of the client connected to this backend. If this field is | Any string |
| The vector distance (similarity) function used by the query, one of the pgvector distance functions |
|
Related documentation
Instrumentation in self-hosted environments
Learn how to set up PostgreSQL monitoring in self-hosted environments with New Relic.
Instrumentation in RDS environments
Learn how to set up PostgreSQL monitoring in RDS environments with New Relic.
Troubleshooting guide
Learn how to troubleshoot common issues with PostgreSQL monitoring.