master
yaml 1,334 lines 57.2 KB
Raw
1 plugin_name: go.d.plugin
2 modules:
3 - meta:
4 id: collector-go.d.plugin-postgres
5 plugin_name: go.d.plugin
6 module_name: postgres
7 monitored_instance:
8 name: PostgreSQL
9 link: https://www.postgresql.org/
10 categories:
11 - data-collection.databases
12 icon_filename: postgres.svg
13 related_resources:
14 integrations:
15 list:
16 - plugin_name: apps.plugin
17 module_name: apps
18 - plugin_name: cgroups.plugin
19 module_name: /sys/fs/cgroup
20 monitored_instance_name: Containers
21 alternative_monitored_instances: []
22 info_provided_to_referring_integrations:
23 description: ""
24 keywords:
25 - db
26 - database
27 - postgres
28 - postgresql
29 - sql
30 overview:
31 multi_instance: true
32 data_collection:
33 metrics_description: |
34 This collector monitors the activity and performance of Postgres servers, collects replication statistics, metrics for each database, table and index, and more.
35 method_description: |
36 It establishes a connection to the Postgres instance via a TCP or UNIX socket.
37 To collect metrics for database tables and indexes, it establishes an additional connection for each discovered database.
38 default_behavior:
39 auto_detection:
40 description: |
41 By default, it detects instances running on localhost by trying to connect as root and netdata using known PostgreSQL TCP and UNIX sockets:
42
43 - 127.0.0.1:5432
44 - /var/run/postgresql/
45 limits:
46 description: |
47 Table and index metrics are not collected for databases with more than 50 tables or 250 indexes.
48 These limits can be changed in the configuration file.
49 performance_impact:
50 description: ""
51 additional_permissions:
52 description: ""
53 supported_platforms:
54 include: []
55 exclude: []
56 setup:
57 prerequisites:
58 list:
59 - title: Create netdata user
60 description: |
61 Create a user with granted `pg_monitor`
62 or `pg_read_all_stat` [built-in role](https://www.postgresql.org/docs/current/predefined-roles.html).
63
64 To create the `netdata` user with these permissions, execute the following in the psql session, as a user with CREATEROLE privileges:
65
66 ```postgresql
67 CREATE USER netdata;
68 GRANT pg_monitor TO netdata;
69 ```
70
71 After creating the new user, restart the Netdata Agent with `sudo systemctl restart netdata`, or
72 the [appropriate method](/docs/netdata-agent/start-stop-restart.md) for your
73 system.
74 configuration:
75 file:
76 name: go.d/postgres.conf
77 options:
78 description: |
79 The following options can be defined globally: update_every, autodetection_retry.
80 folding:
81 title: Config options
82 enabled: true
83 list:
84 - name: update_every
85 description: Data collection interval (seconds).
86 default_value: 1
87 required: false
88 group: Collection
89 - name: autodetection_retry
90 description: Autodetection retry interval (seconds). Set 0 to disable.
91 default_value: 0
92 required: false
93 group: Collection
94
95 - name: dsn
96 description: Postgres connection string (DSN). See [DSN syntax](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING).
97 default_value: postgres://postgres:postgres@127.0.0.1:5432/postgres
98 required: true
99 group: Target
100 - name: cloud_auth.provider
101 description: Cloud auth provider (`none` or `azure_ad`).
102 default_value: none
103 required: false
104 group: Cloud Auth
105 - name: cloud_auth.azure_ad.mode
106 description: Azure AD credential mode (`service_principal`, `managed_identity`, or `default`). Required when `cloud_auth.provider` is `azure_ad`.
107 default_value: ""
108 required: true
109 group: Cloud Auth/Azure
110 - name: cloud_auth.azure_ad.mode_service_principal.tenant_id
111 description: Azure tenant ID. Required for `service_principal` mode.
112 default_value: ""
113 required: false
114 group: Cloud Auth/Azure
115 - name: cloud_auth.azure_ad.mode_service_principal.client_id
116 description: Azure client ID. Required for `service_principal` mode.
117 default_value: ""
118 required: false
119 group: Cloud Auth/Azure
120 - name: cloud_auth.azure_ad.mode_service_principal.client_secret
121 description: Azure client secret for `service_principal` mode.
122 default_value: ""
123 required: false
124 group: Cloud Auth/Azure
125 - name: cloud_auth.azure_ad.mode_managed_identity.client_id
126 description: Optional client ID of a user-assigned managed identity (`managed_identity` mode).
127 default_value: ""
128 required: false
129 group: Cloud Auth/Azure
130 - name: timeout
131 description: Query timeout (seconds).
132 default_value: 2
133 required: false
134 group: Target
135
136 - name: collect_databases_matching
137 description: Database selector. Controls which databases are included. Uses [simple patterns](https://github.com/netdata/netdata/tree/master/src/go/pkg/matcher#simple-patterns-matcher).
138 default_value: ""
139 required: false
140 group: Filters
141
142 - name: max_db_tables
143 description: Maximum number of tables per database to collect metrics for (0 = no limit).
144 default_value: 50
145 required: false
146 group: Limits
147 - name: max_db_indexes
148 description: Maximum number of indexes per database to collect metrics for (0 = no limit).
149 default_value: 250
150 required: false
151 group: Limits
152
153 - name: functions.top_queries.disabled
154 description: Disable the [top-queries](#top-queries) function.
155 default_value: false
156 required: false
157 group: Functions
158 - name: functions.top_queries.timeout
159 description: Query timeout (seconds). Uses collector timeout if not set.
160 default_value: ""
161 required: false
162 group: Functions
163 - name: functions.top_queries.limit
164 description: Maximum number of queries to return.
165 default_value: 500
166 required: false
167 group: Functions
168
169 - name: vnode
170 description: Associates this data collection job with a [Virtual Node](https://learn.netdata.cloud/docs/netdata-agent/configuration/organize-systems-metrics-and-alerts#virtual-nodes).
171 default_value: ""
172 required: false
173 group: Virtual Node
174 examples:
175 folding:
176 title: Config
177 enabled: true
178 list:
179 - name: TCP socket
180 description: An example configuration.
181 folding:
182 enabled: false
183 config: |
184 jobs:
185 - name: local
186 dsn: 'postgresql://netdata@127.0.0.1:5432/postgres'
187 - name: Unix socket
188 description: An example configuration.
189 config: |
190 jobs:
191 - name: local
192 dsn: 'host=/var/run/postgresql dbname=postgres user=netdata'
193 - name: Unix socket (custom port)
194 description: Connect to PostgreSQL using a Unix socket with a non-default port (5433).
195 config: |
196 jobs:
197 - name: local
198 dsn: 'host=/var/run/postgresql port=5433 dbname=postgres user=netdata'
199 - name: Azure Database for PostgreSQL with service principal
200 description: Use Microsoft Entra service principal authentication.
201 config: |
202 jobs:
203 - name: azure_postgres_sp
204 dsn: 'postgresql://netdata@myserver.postgres.database.azure.com:5432/postgres?sslmode=require'
205 cloud_auth:
206 provider: azure_ad
207 azure_ad:
208 mode: service_principal
209 mode_service_principal:
210 tenant_id: "00000000-0000-0000-0000-000000000000"
211 client_id: "11111111-1111-1111-1111-111111111111"
212 client_secret: "super-secret-value"
213 - name: Azure Database for PostgreSQL with managed identity
214 description: Use managed identity authentication (system-assigned by default).
215 config: |
216 jobs:
217 - name: azure_postgres_mi
218 dsn: 'postgresql://netdata@myserver.postgres.database.azure.com:5432/postgres?sslmode=require'
219 cloud_auth:
220 provider: azure_ad
221 azure_ad:
222 mode: managed_identity
223 - name: Multi-instance
224 description: |
225 > **Note**: When you define multiple jobs, their names must be unique.
226
227 Local and remote instances.
228 config: |
229 jobs:
230 - name: local
231 dsn: 'postgresql://netdata@127.0.0.1:5432/postgres'
232
233 - name: remote
234 dsn: 'postgresql://netdata@203.0.113.0:5432/postgres'
235 troubleshooting:
236 problems:
237 list: []
238 alerts:
239 - name: postgres_total_connection_utilization
240 metric: postgres.connections_utilization
241 info: average total connection utilization over the last minute
242 link: https://github.com/netdata/netdata/blob/master/src/health/health.d/postgres.conf
243 - name: postgres_acquired_locks_utilization
244 metric: postgres.locks_utilization
245 info: average acquired locks utilization over the last minute
246 link: https://github.com/netdata/netdata/blob/master/src/health/health.d/postgres.conf
247 - name: postgres_txid_exhaustion_perc
248 metric: postgres.txid_exhaustion_perc
249 info: percent towards TXID wraparound
250 link: https://github.com/netdata/netdata/blob/master/src/health/health.d/postgres.conf
251 - name: postgres_db_cache_io_ratio
252 metric: postgres.db_cache_io_ratio
253 info: average cache hit ratio in db ${label:database} over the last minute
254 link: https://github.com/netdata/netdata/blob/master/src/health/health.d/postgres.conf
255 - name: postgres_db_transactions_rollback_ratio
256 metric: postgres.db_cache_io_ratio
257 info: average aborted transactions percentage in db ${label:database} over the last five minutes
258 link: https://github.com/netdata/netdata/blob/master/src/health/health.d/postgres.conf
259 - name: postgres_db_deadlocks_rate
260 metric: postgres.db_deadlocks_rate
261 info: number of deadlocks detected in db ${label:database} in the last minute
262 link: https://github.com/netdata/netdata/blob/master/src/health/health.d/postgres.conf
263 - name: postgres_table_cache_io_ratio
264 metric: postgres.table_cache_io_ratio
265 info: average cache hit ratio in db ${label:database} table ${label:table} over the last minute
266 link: https://github.com/netdata/netdata/blob/master/src/health/health.d/postgres.conf
267 - name: postgres_table_index_cache_io_ratio
268 metric: postgres.table_index_cache_io_ratio
269 info: average index cache hit ratio in db ${label:database} table ${label:table} over the last minute
270 link: https://github.com/netdata/netdata/blob/master/src/health/health.d/postgres.conf
271 - name: postgres_table_toast_cache_io_ratio
272 metric: postgres.table_toast_cache_io_ratio
273 info: average TOAST hit ratio in db ${label:database} table ${label:table} over the last minute
274 link: https://github.com/netdata/netdata/blob/master/src/health/health.d/postgres.conf
275 - name: postgres_table_toast_index_cache_io_ratio
276 metric: postgres.table_toast_index_cache_io_ratio
277 info: average index TOAST hit ratio in db ${label:database} table ${label:table} over the last minute
278 link: https://github.com/netdata/netdata/blob/master/src/health/health.d/postgres.conf
279 - name: postgres_table_bloat_size_perc
280 metric: postgres.table_bloat_size_perc
281 info: bloat size percentage in db ${label:database} table ${label:table}
282 link: https://github.com/netdata/netdata/blob/master/src/health/health.d/postgres.conf
283 - name: postgres_table_last_autovacuum_time
284 metric: postgres.table_autovacuum_since_time
285 info: time elapsed since db ${label:database} table ${label:table} was vacuumed by the autovacuum daemon
286 link: https://github.com/netdata/netdata/blob/master/src/health/health.d/postgres.conf
287 - name: postgres_table_last_autoanalyze_time
288 metric: postgres.table_autoanalyze_since_time
289 info: time elapsed since db ${label:database} table ${label:table} was analyzed by the autovacuum daemon
290 link: https://github.com/netdata/netdata/blob/master/src/health/health.d/postgres.conf
291 - name: postgres_index_bloat_size_perc
292 metric: postgres.index_bloat_size_perc
293 info: bloat size percentage in db ${label:database} table ${label:table} index ${label:index}
294 link: https://github.com/netdata/netdata/blob/master/src/health/health.d/postgres.conf
295 functions:
296 description: |
297 This collector exposes real-time functions for interactive troubleshooting in the Live tab.
298 list:
299 - id: top-queries
300 name: Top Queries
301 description: |
302 Retrieves aggregated SQL query performance metrics from PostgreSQL using either [pg_stat_monitor](https://docs.percona.com/pg-stat-monitor/) (preferred) or [pg_stat_statements](https://www.postgresql.org/docs/current/pgstatstatements.html).
303
304 The collector automatically detects which extension is available:
305 - **pg_stat_monitor** (Percona): Enhanced statistics with additional columns like application name, client IP, CPU time, error info, and query classification
306 - **pg_stat_statements** (standard): Core execution statistics available in all PostgreSQL installations
307
308 Statistics include execution counts, timing metrics, I/O operations, and resource consumption. Columns are dynamically detected based on your PostgreSQL version and available extension.
309
310 Use cases:
311 - Identify slow queries consuming the most total execution time
312 - Find queries with high shared block reads for I/O optimization
313 - Analyze temp block usage to detect queries needing memory tuning
314 - With pg_stat_monitor: Track queries by application, identify error patterns
315
316 Query text is truncated at 4096 characters for display purposes.
317 parameters:
318 - id: __sort
319 name: Filter By
320 description: Select the primary sort column. Options include total time, mean time, calls, rows, shared blocks hit/read, and temp blocks written. Defaults to total time to focus on most resource-intensive queries.
321 type: select
322 required: true
323 default: totalTime
324 options: []
325 returns:
326 description: Aggregated query statistics from `pg_stat_statements` or `pg_stat_monitor`. Each row represents a unique query pattern with cumulative metrics across all executions.
327 columns:
328 - name: Query ID
329 type: string
330 unit: ""
331 visibility: hidden
332 description: "Internal hash identifier for the normalized query. Can be used to track queries across statistics resets."
333 - name: Query
334 type: string
335 unit: ""
336 description: "Normalized SQL query text with literals replaced by parameter placeholders. Truncated to 4096 characters."
337 - name: Database
338 type: string
339 unit: ""
340 description: "Database name where the query was executed."
341 - name: User
342 type: string
343 unit: ""
344 description: "PostgreSQL user who executed the query."
345 - name: Calls
346 type: integer
347 unit: ""
348 description: "Total number of times this query pattern has been executed. High values indicate frequently run queries."
349 - name: Total Time
350 type: duration
351 unit: "milliseconds"
352 description: "Cumulative execution time across all executions. High values indicate queries consuming significant database resources."
353 - name: Mean Time
354 type: duration
355 unit: "milliseconds"
356 description: "Average execution time per call. Use this to compare typical performance across different query patterns."
357 - name: Min Time
358 type: duration
359 unit: "milliseconds"
360 visibility: hidden
361 description: "Minimum execution time observed for a single execution."
362 - name: Max Time
363 type: duration
364 unit: "milliseconds"
365 visibility: hidden
366 description: "Maximum execution time observed for a single execution. Large gaps between min and max may indicate performance variability."
367 - name: Stddev Time
368 type: duration
369 unit: "milliseconds"
370 visibility: hidden
371 description: "Standard deviation of execution time. High values indicate inconsistent query performance."
372 - name: Plans
373 type: integer
374 unit: ""
375 visibility: hidden
376 description: "Number of times the query was planned. Available in PostgreSQL 13+."
377 - name: Total Plan Time
378 type: duration
379 unit: "milliseconds"
380 visibility: hidden
381 description: "Cumulative time spent planning the query. Available in PostgreSQL 13+."
382 - name: Mean Plan Time
383 type: duration
384 unit: "milliseconds"
385 visibility: hidden
386 description: "Average time spent planning per execution. Available in PostgreSQL 13+."
387 - name: Min Plan Time
388 type: duration
389 unit: "milliseconds"
390 visibility: hidden
391 description: "Minimum planning time observed. Available in PostgreSQL 13+."
392 - name: Max Plan Time
393 type: duration
394 unit: "milliseconds"
395 visibility: hidden
396 description: "Maximum planning time observed. Available in PostgreSQL 13+."
397 - name: Stddev Plan Time
398 type: duration
399 unit: "milliseconds"
400 visibility: hidden
401 description: "Standard deviation of planning time. Available in PostgreSQL 13+."
402 - name: Rows
403 type: integer
404 unit: ""
405 description: "Total number of rows retrieved or affected across all executions."
406 - name: Shared Blocks Hit
407 type: integer
408 unit: ""
409 description: "Total shared buffer cache hits. High values indicate good cache utilization."
410 - name: Shared Blocks Read
411 type: integer
412 unit: ""
413 description: "Total shared blocks read from disk. High values indicate queries that bypass the cache and may benefit from more `shared_buffers`."
414 - name: Shared Blocks Dirtied
415 type: integer
416 unit: ""
417 visibility: hidden
418 description: "Total shared blocks dirtied by the query."
419 - name: Shared Blocks Written
420 type: integer
421 unit: ""
422 visibility: hidden
423 description: "Total shared blocks written by the query."
424 - name: Local Blocks Hit
425 type: integer
426 unit: ""
427 visibility: hidden
428 description: "Total local buffer cache hits (temporary tables)."
429 - name: Local Blocks Read
430 type: integer
431 unit: ""
432 visibility: hidden
433 description: "Total local blocks read from disk."
434 - name: Local Blocks Dirtied
435 type: integer
436 unit: ""
437 visibility: hidden
438 description: "Total local blocks dirtied."
439 - name: Local Blocks Written
440 type: integer
441 unit: ""
442 visibility: hidden
443 description: "Total local blocks written."
444 - name: Temp Blocks Read
445 type: integer
446 unit: ""
447 description: "Total temp blocks read. Non-zero values indicate queries spilling to disk due to insufficient `work_mem`."
448 - name: Temp Blocks Written
449 type: integer
450 unit: ""
451 description: "Total temp blocks written. High values suggest increasing `work_mem` may improve performance."
452 - name: Block Read Time
453 type: duration
454 unit: "milliseconds"
455 description: "Time spent reading blocks from disk. Requires `track_io_timing` to be enabled."
456 - name: Block Write Time
457 type: duration
458 unit: "milliseconds"
459 description: "Time spent writing blocks to disk. Requires `track_io_timing` to be enabled."
460 - name: WAL Records
461 type: integer
462 unit: ""
463 visibility: hidden
464 description: "Total number of WAL records generated. Available in PostgreSQL 13+."
465 - name: WAL Full Page Images
466 type: integer
467 unit: ""
468 visibility: hidden
469 description: "Total number of WAL full page images generated. Available in PostgreSQL 13+."
470 - name: WAL Bytes
471 type: integer
472 unit: ""
473 visibility: hidden
474 description: "Total bytes of WAL generated. Available in PostgreSQL 13+."
475 - name: JIT Functions
476 type: integer
477 unit: ""
478 visibility: hidden
479 description: "Total number of functions JIT-compiled. Available in PostgreSQL 15+."
480 - name: JIT Generation Time
481 type: duration
482 unit: "milliseconds"
483 visibility: hidden
484 description: "Time spent generating JIT code. Available in PostgreSQL 15+."
485 - name: JIT Inlining Count
486 type: integer
487 unit: ""
488 visibility: hidden
489 description: "Number of times JIT inlining was performed. Available in PostgreSQL 15+."
490 - name: JIT Inlining Time
491 type: duration
492 unit: "milliseconds"
493 visibility: hidden
494 description: "Time spent on JIT inlining. Available in PostgreSQL 15+."
495 - name: JIT Optimization Count
496 type: integer
497 unit: ""
498 visibility: hidden
499 description: "Number of times JIT optimization was performed. Available in PostgreSQL 15+."
500 - name: JIT Optimization Time
501 type: duration
502 unit: "milliseconds"
503 visibility: hidden
504 description: "Time spent on JIT optimization. Available in PostgreSQL 15+."
505 - name: JIT Emission Count
506 type: integer
507 unit: ""
508 visibility: hidden
509 description: "Number of times JIT code was emitted. Available in PostgreSQL 15+."
510 - name: JIT Emission Time
511 type: duration
512 unit: "milliseconds"
513 visibility: hidden
514 description: "Time spent emitting JIT code. Available in PostgreSQL 15+."
515 - name: Temp Block Read Time
516 type: duration
517 unit: "milliseconds"
518 visibility: hidden
519 description: "Time spent reading temp blocks. Available in PostgreSQL 15+. Requires `track_io_timing`."
520 - name: Temp Block Write Time
521 type: duration
522 unit: "milliseconds"
523 visibility: hidden
524 description: "Time spent writing temp blocks. Available in PostgreSQL 15+. Requires `track_io_timing`."
525 - name: Application Name
526 type: string
527 unit: ""
528 description: "Name of the application that executed the query. Available with pg_stat_monitor only."
529 - name: Client IP
530 type: string
531 unit: ""
532 visibility: hidden
533 description: "IP address of the client that executed the query. Available with pg_stat_monitor only."
534 - name: Command Type
535 type: string
536 unit: ""
537 description: "Type of SQL command (SELECT, INSERT, UPDATE, DELETE, etc.). Available with pg_stat_monitor only."
538 - name: Comments
539 type: string
540 unit: ""
541 visibility: hidden
542 description: "SQL comments extracted from the query. Available with pg_stat_monitor only."
543 - name: Relations
544 type: string
545 unit: ""
546 visibility: hidden
547 description: "Tables/relations involved in the query. Available with pg_stat_monitor only."
548 - name: CPU User Time
549 type: duration
550 unit: "milliseconds"
551 visibility: hidden
552 description: "CPU time spent in user mode. Available with pg_stat_monitor only."
553 - name: CPU System Time
554 type: duration
555 unit: "milliseconds"
556 visibility: hidden
557 description: "CPU time spent in system/kernel mode. Available with pg_stat_monitor only."
558 - name: Error Level
559 type: integer
560 unit: ""
561 visibility: hidden
562 description: "PostgreSQL error level if query produced an error. Available with pg_stat_monitor only."
563 - name: SQL Code
564 type: string
565 unit: ""
566 visibility: hidden
567 description: "PostgreSQL SQLSTATE error code if query produced an error. Available with pg_stat_monitor only."
568 - name: Error Message
569 type: string
570 unit: ""
571 visibility: hidden
572 description: "Error message if query produced an error. Available with pg_stat_monitor only."
573 - name: Top Level
574 type: string
575 unit: ""
576 visibility: hidden
577 description: "Whether this is a top-level statement (true) or nested (false). Available with pg_stat_monitor only."
578 - name: Bucket Start Time
579 type: string
580 unit: ""
581 visibility: hidden
582 description: "Start time of the statistics bucket. Available with pg_stat_monitor only."
583 performance: |
584 Queries `pg_stat_statements` or `pg_stat_monitor` which maintain statistics in shared memory:<br/>• On busy servers with many unique queries, the extension may consume significant memory<br/>• Default limit of 500 rows balances usefulness with performance<br/>• pg_stat_monitor uses time-based buckets which may have different memory characteristics
585 security: |
586 Query text may contain unmasked literal values including potentially sensitive data:<br/>• Personal information in WHERE clauses or INSERT values<br/>• Business data and internal identifiers<br/>• Access should be restricted to authorized personnel only
587 prerequisites:
588 list:
589 - title: Enable pg_stat_statements or pg_stat_monitor
590 description: |
591 Either `pg_stat_statements` (standard) or `pg_stat_monitor` (Percona) must be installed. The collector auto-detects which is available, preferring pg_stat_monitor when both are present.
592
593 **Option 1: pg_stat_statements (standard PostgreSQL)**
594
595 1. Add to `postgresql.conf`:
596
597 ```ini
598 shared_preload_libraries = 'pg_stat_statements'
599 ```
600
601 2. Restart PostgreSQL, then create the extension:
602
603 ```sql
604 CREATE EXTENSION pg_stat_statements;
605 ```
606
607 **Option 2: pg_stat_monitor (Percona - recommended)**
608
609 Provides additional columns: application name, client IP, CPU time, error tracking, and query classification.
610
611 1. Install pg_stat_monitor (available in Percona distribution or as separate package)
612
613 2. Add to `postgresql.conf`:
614
615 ```ini
616 shared_preload_libraries = 'pg_stat_monitor'
617 ```
618
619 3. Restart PostgreSQL, then create the extension:
620
621 ```sql
622 CREATE EXTENSION pg_stat_monitor;
623 ```
624
625 :::info
626
627 - Both extensions require a server restart to load the shared library
628 - Statistics can be reset with `SELECT pg_stat_statements_reset()` or `SELECT pg_stat_monitor_reset()`
629 - Enable `track_io_timing` for block read/write timing metrics
630
631 :::
632 availability: |
633 Available when:<br/>• Either `pg_stat_statements` or `pg_stat_monitor` extension is installed<br/>• The collector has successfully connected to PostgreSQL<br/>• Returns HTTP 503 if no query statistics extension is installed<br/>• Returns HTTP 500 if the query fails<br/>• Returns HTTP 504 if the query times out
634 require_cloud: true
635 - id: running-queries
636 name: Running Queries
637 description: |
638 Retrieves currently executing queries from PostgreSQL [pg_stat_activity](https://www.postgresql.org/docs/current/monitoring-stats.html#MONITORING-PG-STAT-ACTIVITY-VIEW) system view.
639
640 This function queries `pg_stat_activity` which shows real-time information about each server process including the SQL query being executed, wait events, and session state. Unlike Top Queries which shows aggregated historical statistics, Running Queries shows live snapshots of active queries.
641
642 Use cases:
643 - Identify long-running queries that may be blocking other operations
644 - Debug stuck transactions or hanging connections
645 - Monitor active workload during performance issues
646 - Investigate wait events and lock contention in real-time
647
648 Query text is truncated at 4096 characters for display purposes.
649 parameters:
650 - id: __sort
651 name: Sort By
652 description: Select the sort column. Defaults to query duration (longest running first).
653 type: select
654 required: true
655 default: durationMs
656 options: []
657 returns:
658 description: Live query data from `pg_stat_activity`. Each row represents a currently active backend process.
659 columns:
660 # Visible columns (most important first)
661 - name: Duration
662 type: duration
663 unit: "milliseconds"
664 description: "Query duration in milliseconds (since query_start). High values indicate long-running queries."
665 - name: Query
666 type: string
667 unit: ""
668 description: "Query text of the currently executing or most recent query. May be truncated at track_activity_query_size."
669 - name: Database
670 type: string
671 unit: ""
672 description: "Name of the database this backend is connected to."
673 - name: User
674 type: string
675 unit: ""
676 description: "Name of the user logged into this backend."
677 - name: Application Name
678 type: string
679 unit: ""
680 description: "Name of the application connected to this backend."
681 - name: Client Address
682 type: string
683 unit: ""
684 description: "IP address of the client (NULL for Unix socket or internal process)."
685 - name: Wait Event
686 type: string
687 unit: ""
688 description: "Specific wait event name if backend is currently waiting."
689 - name: PID
690 type: integer
691 unit: ""
692 description: "Process ID of this backend. Use with pg_terminate_backend() to kill a query."
693 # Hidden columns
694 - name: Wait Event Type
695 type: string
696 unit: ""
697 visibility: hidden
698 description: "Type of event the backend is waiting for (Activity, BufferPin, Client, Extension, IO, IPC, Lock, LWLock, Timeout)."
699 - name: State
700 type: string
701 unit: ""
702 visibility: hidden
703 description: "Current state: active, idle, idle in transaction, idle in transaction (aborted), fastpath function call, disabled."
704 - name: Backend Type
705 type: string
706 unit: ""
707 visibility: hidden
708 description: "Type of backend: client backend, autovacuum worker, parallel worker, walsender, walreceiver, etc. Available in PostgreSQL 10+."
709 - name: Query Start
710 type: timestamp
711 unit: ""
712 visibility: hidden
713 description: "Time when the currently active query was started."
714 - name: Transaction Start
715 type: timestamp
716 unit: ""
717 visibility: hidden
718 description: "Time when current transaction started (NULL if no transaction)."
719 - name: Backend Start
720 type: timestamp
721 unit: ""
722 visibility: hidden
723 description: "Time when this process/connection started."
724 - name: State Change
725 type: timestamp
726 unit: ""
727 visibility: hidden
728 description: "Time when state was last changed."
729 - name: Query ID
730 type: string
731 unit: ""
732 visibility: hidden
733 description: "Query identifier (requires compute_query_id or extension). Available in PostgreSQL 14+."
734 - name: Leader PID
735 type: integer
736 unit: ""
737 visibility: hidden
738 description: "Process ID of parallel group leader (NULL if this is leader or not parallel). Available in PostgreSQL 13+."
739 - name: Database ID
740 type: integer
741 unit: ""
742 visibility: hidden
743 description: "OID of the database this backend is connected to."
744 - name: User ID
745 type: integer
746 unit: ""
747 visibility: hidden
748 description: "OID of the user logged into this backend."
749 - name: Client Hostname
750 type: string
751 unit: ""
752 visibility: hidden
753 description: "Hostname of the client via reverse DNS (only if log_hostname enabled)."
754 - name: Client Port
755 type: integer
756 unit: ""
757 visibility: hidden
758 description: "TCP port of client (-1 for Unix socket, NULL for internal process)."
759 - name: Backend Xid
760 type: string
761 unit: ""
762 visibility: hidden
763 description: "Top-level transaction identifier of this backend."
764 - name: Backend Xmin
765 type: string
766 unit: ""
767 visibility: hidden
768 description: "Backend's xmin horizon."
769 performance: |
770 Queries `pg_stat_activity` which is a live system view:<br/>• Very lightweight query, no impact on database performance<br/>• Returns only active queries by default (state = 'active')<br/>• Limited to 500 rows
771 security: |
772 Query text contains actual SQL being executed, which may include:<br/>• Personal information in WHERE clauses or INSERT values<br/>• Business data and internal identifiers<br/>• Access should be restricted to authorized personnel only
773 prerequisites:
774 list:
775 - title: Database user permissions
776 description: |
777 The monitoring user needs `pg_monitor` role to view all sessions:
778
779 ```sql
780 GRANT pg_monitor TO netdata;
781 ```
782
783 Without this role, the user can only see their own sessions.
784 availability: |
785 Available when:<br/>• The collector has successfully connected to PostgreSQL<br/>• Returns HTTP 503 if collector is still initializing<br/>• Returns HTTP 500 if the query fails<br/>• Returns HTTP 504 if the query times out
786 require_cloud: true
787 metrics:
788 folding:
789 title: Metrics
790 enabled: false
791 description: ""
792 availability: []
793 scopes:
794 - name: global
795 description: These metrics refer to the entire monitored application.
796 labels: []
797 metrics:
798 - name: postgres.connections_utilization
799 description: Connections utilization
800 unit: percentage
801 chart_type: line
802 dimensions:
803 - name: used
804 - name: postgres.connections_usage
805 description: Connections usage
806 unit: connections
807 chart_type: stacked
808 dimensions:
809 - name: available
810 - name: used
811 - name: postgres.connections_state_count
812 description: Connections in each state
813 unit: connections
814 chart_type: stacked
815 dimensions:
816 - name: active
817 - name: idle
818 - name: idle_in_transaction
819 - name: idle_in_transaction_aborted
820 - name: disabled
821 - name: postgres.transactions_duration
822 description: Observed transactions time
823 unit: transactions/s
824 chart_type: stacked
825 dimensions:
826 - name: a dimension per bucket
827 - name: postgres.queries_duration
828 description: Observed active queries time
829 unit: queries/s
830 chart_type: stacked
831 dimensions:
832 - name: a dimension per bucket
833 - name: postgres.locks_utilization
834 description: Acquired locks utilization
835 unit: percentage
836 chart_type: line
837 dimensions:
838 - name: used
839 - name: postgres.checkpoints_rate
840 description: Checkpoints
841 unit: checkpoints/s
842 chart_type: stacked
843 dimensions:
844 - name: scheduled
845 - name: requested
846 - name: postgres.checkpoints_time
847 description: Checkpoint time
848 unit: milliseconds
849 chart_type: stacked
850 dimensions:
851 - name: write
852 - name: sync
853 - name: postgres.bgwriter_halts_rate
854 description: Background writer scan halts
855 unit: events/s
856 chart_type: line
857 dimensions:
858 - name: maxwritten
859 - name: postgres.buffers_io_rate
860 description: Buffers written rate
861 unit: B/s
862 chart_type: area
863 dimensions:
864 - name: checkpoint
865 - name: backend
866 - name: bgwriter
867 - name: postgres.buffers_backend_fsync_rate
868 description: Backend fsync calls
869 unit: calls/s
870 chart_type: line
871 dimensions:
872 - name: fsync
873 - name: postgres.buffers_allocated_rate
874 description: Buffers allocated
875 unit: B/s
876 chart_type: line
877 dimensions:
878 - name: allocated
879 - name: postgres.wal_io_rate
880 description: Write-Ahead Log writes
881 unit: B/s
882 chart_type: line
883 dimensions:
884 - name: write
885 - name: postgres.wal_files_count
886 description: Write-Ahead Log files
887 unit: files
888 chart_type: stacked
889 dimensions:
890 - name: written
891 - name: recycled
892 - name: postgres.wal_archiving_files_count
893 description: Write-Ahead Log archived files
894 unit: files/s
895 chart_type: stacked
896 dimensions:
897 - name: ready
898 - name: done
899 - name: postgres.autovacuum_workers_count
900 description: Autovacuum workers
901 unit: workers
902 chart_type: line
903 dimensions:
904 - name: analyze
905 - name: vacuum_analyze
906 - name: vacuum
907 - name: vacuum_freeze
908 - name: brin_summarize
909 - name: postgres.txid_exhaustion_towards_autovacuum_perc
910 description: Percent towards emergency autovacuum
911 unit: percentage
912 chart_type: line
913 dimensions:
914 - name: emergency_autovacuum
915 - name: postgres.txid_exhaustion_perc
916 description: Percent towards transaction ID wraparound
917 unit: percentage
918 chart_type: line
919 dimensions:
920 - name: txid_exhaustion
921 - name: postgres.txid_exhaustion_oldest_txid_num
922 description: Oldest transaction XID
923 chart_type: line
924 unit: xid
925 dimensions:
926 - name: xid
927 - name: postgres.catalog_relations_count
928 description: Relation count
929 unit: relations
930 chart_type: stacked
931 dimensions:
932 - name: ordinary_table
933 - name: index
934 - name: sequence
935 - name: toast_table
936 - name: view
937 - name: materialized_view
938 - name: composite_type
939 - name: foreign_table
940 - name: partitioned_table
941 - name: partitioned_index
942 - name: postgres.catalog_relations_size
943 description: Relation size
944 unit: B
945 chart_type: stacked
946 dimensions:
947 - name: ordinary_table
948 - name: index
949 - name: sequence
950 - name: toast_table
951 - name: view
952 - name: materialized_view
953 - name: composite_type
954 - name: foreign_table
955 - name: partitioned_table
956 - name: partitioned_index
957 - name: postgres.uptime
958 description: Uptime
959 unit: seconds
960 chart_type: line
961 dimensions:
962 - name: uptime
963 - name: postgres.databases_count
964 description: Number of databases
965 unit: databases
966 chart_type: line
967 dimensions:
968 - name: databases
969 - name: repl application
970 description: These metrics refer to the replication application.
971 labels:
972 - name: application
973 description: application name
974 metrics:
975 - name: postgres.replication_app_wal_lag_size
976 description: Standby application WAL lag size
977 unit: B
978 chart_type: line
979 dimensions:
980 - name: sent_lag
981 - name: write_lag
982 - name: flush_lag
983 - name: replay_lag
984 - name: postgres.replication_app_wal_lag_time
985 description: Standby application WAL lag time
986 unit: seconds
987 chart_type: line
988 dimensions:
989 - name: write_lag
990 - name: flush_lag
991 - name: replay_lag
992 - name: repl slot
993 description: These metrics refer to the replication slot.
994 labels:
995 - name: slot
996 description: replication slot name
997 metrics:
998 - name: postgres.replication_slot_files_count
999 description: Replication slot files
1000 unit: files
1001 chart_type: line
1002 dimensions:
1003 - name: wal_keep
1004 - name: pg_replslot_files
1005 - name: database
1006 description: These metrics refer to the database.
1007 labels:
1008 - name: database
1009 description: database name
1010 metrics:
1011 - name: postgres.db_transactions_ratio
1012 description: Database transactions ratio
1013 unit: percentage
1014 chart_type: line
1015 dimensions:
1016 - name: committed
1017 - name: rollback
1018 - name: postgres.db_transactions_rate
1019 description: Database transactions
1020 unit: transactions/s
1021 chart_type: line
1022 dimensions:
1023 - name: committed
1024 - name: rollback
1025 - name: postgres.db_connections_utilization
1026 description: Database connections utilization
1027 unit: percentage
1028 chart_type: line
1029 dimensions:
1030 - name: used
1031 - name: postgres.db_connections_count
1032 description: Database connections
1033 unit: connections
1034 chart_type: line
1035 dimensions:
1036 - name: connections
1037 - name: postgres.db_cache_io_ratio
1038 description: Database buffer cache miss ratio
1039 unit: percentage
1040 chart_type: line
1041 dimensions:
1042 - name: miss
1043 - name: postgres.db_io_rate
1044 description: Database reads
1045 unit: B/s
1046 chart_type: line
1047 dimensions:
1048 - name: memory
1049 - name: disk
1050 - name: postgres.db_ops_fetched_rows_ratio
1051 description: Database rows fetched ratio
1052 unit: percentage
1053 chart_type: line
1054 dimensions:
1055 - name: fetched
1056 - name: postgres.db_ops_read_rows_rate
1057 description: Database rows read
1058 unit: rows/s
1059 chart_type: line
1060 dimensions:
1061 - name: returned
1062 - name: fetched
1063 - name: postgres.db_ops_write_rows_rate
1064 description: Database rows written
1065 unit: rows/s
1066 chart_type: line
1067 dimensions:
1068 - name: inserted
1069 - name: deleted
1070 - name: updated
1071 - name: postgres.db_conflicts_rate
1072 description: Database canceled queries
1073 unit: queries/s
1074 chart_type: line
1075 dimensions:
1076 - name: conflicts
1077 - name: postgres.db_conflicts_reason_rate
1078 description: Database canceled queries by reason
1079 unit: queries/s
1080 chart_type: line
1081 dimensions:
1082 - name: tablespace
1083 - name: lock
1084 - name: snapshot
1085 - name: bufferpin
1086 - name: deadlock
1087 - name: postgres.db_deadlocks_rate
1088 description: Database deadlocks
1089 unit: deadlocks/s
1090 chart_type: line
1091 dimensions:
1092 - name: deadlocks
1093 - name: postgres.db_locks_held_count
1094 description: Database locks held
1095 unit: locks
1096 chart_type: stacked
1097 dimensions:
1098 - name: access_share
1099 - name: row_share
1100 - name: row_exclusive
1101 - name: share_update
1102 - name: share
1103 - name: share_row_exclusive
1104 - name: exclusive
1105 - name: access_exclusive
1106 - name: postgres.db_locks_awaited_count
1107 description: Database locks awaited
1108 unit: locks
1109 chart_type: stacked
1110 dimensions:
1111 - name: access_share
1112 - name: row_share
1113 - name: row_exclusive
1114 - name: share_update
1115 - name: share
1116 - name: share_row_exclusive
1117 - name: exclusive
1118 - name: access_exclusive
1119 - name: postgres.db_temp_files_created_rate
1120 description: Database created temporary files
1121 unit: files/s
1122 chart_type: line
1123 dimensions:
1124 - name: created
1125 - name: postgres.db_temp_files_io_rate
1126 description: Database temporary files data written to disk
1127 unit: B/s
1128 chart_type: line
1129 dimensions:
1130 - name: written
1131 - name: postgres.db_size
1132 description: Database size
1133 unit: B
1134 chart_type: line
1135 dimensions:
1136 - name: size
1137 - name: table
1138 description: These metrics refer to the database table.
1139 labels:
1140 - name: database
1141 description: database name
1142 - name: schema
1143 description: schema name
1144 - name: table
1145 description: table name
1146 - name: parent_table
1147 description: parent table name
1148 metrics:
1149 - name: postgres.table_rows_dead_ratio
1150 description: Table dead rows
1151 unit: percentage
1152 chart_type: line
1153 dimensions:
1154 - name: dead
1155 - name: postgres.table_rows_count
1156 description: Table total rows
1157 unit: rows
1158 chart_type: line
1159 dimensions:
1160 - name: live
1161 - name: dead
1162 - name: postgres.table_ops_rows_rate
1163 description: Table throughput
1164 unit: rows/s
1165 chart_type: line
1166 dimensions:
1167 - name: inserted
1168 - name: deleted
1169 - name: updated
1170 - name: postgres.table_ops_rows_hot_ratio
1171 description: Table HOT updates ratio
1172 unit: percentage
1173 chart_type: line
1174 dimensions:
1175 - name: hot
1176 - name: postgres.table_ops_rows_hot_rate
1177 description: Table HOT updates
1178 unit: rows/s
1179 chart_type: line
1180 dimensions:
1181 - name: hot
1182 - name: postgres.table_cache_io_ratio
1183 description: Table I/O cache miss ratio
1184 unit: percentage
1185 chart_type: line
1186 dimensions:
1187 - name: miss
1188 - name: postgres.table_io_rate
1189 description: Table I/O
1190 unit: B/s
1191 chart_type: line
1192 dimensions:
1193 - name: memory
1194 - name: disk
1195 - name: postgres.table_index_cache_io_ratio
1196 description: Table index I/O cache miss ratio
1197 unit: percentage
1198 chart_type: line
1199 dimensions:
1200 - name: miss
1201 - name: postgres.table_index_io_rate
1202 description: Table index I/O
1203 unit: B/s
1204 chart_type: line
1205 dimensions:
1206 - name: memory
1207 - name: disk
1208 - name: postgres.table_toast_cache_io_ratio
1209 description: Table TOAST I/O cache miss ratio
1210 unit: percentage
1211 chart_type: line
1212 dimensions:
1213 - name: miss
1214 - name: postgres.table_toast_io_rate
1215 description: Table TOAST I/O
1216 unit: B/s
1217 chart_type: line
1218 dimensions:
1219 - name: memory
1220 - name: disk
1221 - name: postgres.table_toast_index_cache_io_ratio
1222 description: Table TOAST index I/O cache miss ratio
1223 unit: percentage
1224 chart_type: line
1225 dimensions:
1226 - name: miss
1227 - name: postgres.table_toast_index_io_rate
1228 description: Table TOAST index I/O
1229 unit: B/s
1230 chart_type: line
1231 dimensions:
1232 - name: memory
1233 - name: disk
1234 - name: postgres.table_scans_rate
1235 description: Table scans
1236 unit: scans/s
1237 chart_type: line
1238 dimensions:
1239 - name: index
1240 - name: sequential
1241 - name: postgres.table_scans_rows_rate
1242 description: Table live rows fetched by scans
1243 unit: rows/s
1244 chart_type: line
1245 dimensions:
1246 - name: index
1247 - name: sequential
1248 - name: postgres.table_autovacuum_since_time
1249 description: Table time since last auto VACUUM
1250 unit: seconds
1251 chart_type: line
1252 dimensions:
1253 - name: time
1254 - name: postgres.table_vacuum_since_time
1255 description: Table time since last manual VACUUM
1256 unit: seconds
1257 chart_type: line
1258 dimensions:
1259 - name: time
1260 - name: postgres.table_autoanalyze_since_time
1261 description: Table time since last auto ANALYZE
1262 unit: seconds
1263 chart_type: line
1264 dimensions:
1265 - name: time
1266 - name: postgres.table_analyze_since_time
1267 description: Table time since last manual ANALYZE
1268 unit: seconds
1269 chart_type: line
1270 dimensions:
1271 - name: time
1272 - name: postgres.table_null_columns
1273 description: Table null columns
1274 unit: columns
1275 chart_type: line
1276 dimensions:
1277 - name: "null"
1278 - name: postgres.table_size
1279 description: Table total size
1280 unit: B
1281 chart_type: line
1282 dimensions:
1283 - name: size
1284 - name: postgres.table_bloat_size_perc
1285 description: Table bloat size percentage
1286 unit: percentage
1287 chart_type: line
1288 dimensions:
1289 - name: bloat
1290 - name: postgres.table_bloat_size
1291 description: Table bloat size
1292 unit: B
1293 chart_type: line
1294 dimensions:
1295 - name: bloat
1296 - name: index
1297 description: These metrics refer to the table index.
1298 labels:
1299 - name: database
1300 description: database name
1301 - name: schema
1302 description: schema name
1303 - name: table
1304 description: table name
1305 - name: parent_table
1306 description: parent table name
1307 - name: index
1308 description: index name
1309 metrics:
1310 - name: postgres.index_size
1311 description: Index size
1312 unit: B
1313 chart_type: line
1314 dimensions:
1315 - name: size
1316 - name: postgres.index_bloat_size_perc
1317 description: Index bloat size percentage
1318 unit: percentage
1319 chart_type: line
1320 dimensions:
1321 - name: bloat
1322 - name: postgres.index_bloat_size
1323 description: Index bloat size
1324 unit: B
1325 chart_type: line
1326 dimensions:
1327 - name: bloat
1328 - name: postgres.index_usage_status
1329 description: Index usage status
1330 unit: status
1331 chart_type: line
1332 dimensions:
1333 - name: used
1334 - name: unused