Project: Netdata (Observability and Analysis / Observability)
File: postgresql.md

<!--startmeta customediturl: "https://github.com/netdata/netdata/edit/master/src/go/collectors/go.d.plugin/modules/postgres/README.md" meta_yaml: "https://github.com/netdata/netdata/edit/master/src/go/collectors/go.d.plugin/modules/postgres/metadata.yaml" sidebar_label: "PostgreSQL" learn_status: "Published" learnrelpath: "Collecting Metrics/Databases" most_popular: True message: "DO NOT EDIT THIS FILE DIRECTLY, IT IS GENERATED BY THE COLLECTOR'S metadata.yaml FILE" endmeta--> <img src="https://netdata.cloud/img/postgres.svg" width="150"/> Plugin: go.d.plugin Module: postgres <img src="https://img.shields.io/badge/maintained%20by-Netdata-%2300ab44" /> This collector monitors the activity and performance of Postgres servers, collects replication statistics, metrics for each database, table and index, and more. It establishes a connection to the Postgres instance via a TCP or UNIX socket. To collect metrics for database tables and indexes, it establishes an additional connection for each discovered database. This collector is supported on all platforms. This collector supports collecting metrics from multiple instances of this integration, including remote instances. By default, it detects instances running on localhost by trying to connect as root and netdata using known PostgreSQL TCP and UNIX sockets: 127.0.0.1:5432 /var/run/postgresql/ Table and index metrics are not collected for databases with more than 50 tables or 250 indexes. These limits can be changed in the configuration file. The default configuration for this integration is not expected to impose a significant performance impact on the system. Metrics grouped by scope. The scope defines the instance that the metric belongs to. An instance is uniquely identified by a set of labels. These metrics refer to the entire monitored application. This scope has no labels. Metrics: | Metric | Dimensions | Unit | |:|:-|:-| | postgres.connections_utilization | used | percentage | | postgres.connections_usage | available, used | connections | | postgres.connectionsstatecount | active, idle, idleintransaction, idleintransaction_aborted, disabled | connections | | postgres.transactions_duration | a dimension per bucket | transactions/s | | postgres.queries_duration | a dimension per bucket | queries/s | | postgres.locks_utilization | used | percentage | | postgres.checkpoints_rate | scheduled, requested | checkpoints/s | | postgres.checkpoints_time | write, sync | milliseconds | | postgres.bgwriterhaltsrate | maxwritten | events/s | | postgres.buffersiorate | checkpoint, backend, bgwriter | B/s | | postgres.buffersbackendfsync_rate | fsync | calls/s | | postgres.buffersallocatedrate | allocated | B/s | | postgres.waliorate | write | B/s | | postgres.walfilescount | written, recycled | files | | postgres.walarchivingfiles_count | ready, done | files/s | | postgres.autovacuumworkerscount | analyze, vacuumanalyze, vacuum, vacuumfreeze, brin_summarize | workers | | postgres.txidexhaustiontowardsautovacuumperc | emergency_autovacuum | percentage | | postgres.txidexhaustionperc | txid_exhaustion | percentage | | postgres.txidexhaustionoldesttxidnum | xid | xid | | postgres.catalogrelationscount | ordinarytable, index, sequence, toasttable, view, materializedview, compositetype, foreigntable, partitionedtable, partitioned_index | relations | | postgres.catalogrelationssize | ordinarytable, index, sequence, toasttable, view, materializedview, compositetype, foreigntable, partitionedtable, partitioned_index | B | | postgres.uptime | uptime | seconds | | postgres.databases_count | databases | databases | These metrics refer to the replication application. Labels: | Label | Description | |:--|:-| | application | application name | Metrics: | Metric | Dimensions | Unit | |:|:-|:-| | postgres.replicationappwallagsize | sentlag, writelag, flushlag, replaylag | B | | postgres.replicationappwallagtime | writelag, flushlag, replay_lag | seconds | These metrics refer to the replication slot. Labels: | Label | Description | |:--|:-| | slot | replication slot name | Metrics: | Metric | Dimensions | Unit | |:|:-|:-| | postgres.replicationslotfilescount | walkeep, pgreplslotfiles | files | These metrics refer to the

Labels: | Label | Description | |:--|:-| | database | database name | Metrics: | Metric | Dimensions | Unit | |:|:-|:-| | postgres.dbtransactionsratio | committed, rollback | percentage | | postgres.dbtransactionsrate | committed, rollback | transactions/s | | postgres.dbconnectionsutilization | used | percentage | | postgres.dbconnectionscount | connections | connections | | postgres.dbcacheio_ratio | miss | percentage | | postgres.dbiorate | memory, disk | B/s | | postgres.dbopsfetchedrowsratio | fetched | percentage | | postgres.dbopsreadrowsrate | returned, fetched | rows/s | | postgres.dbopswriterowsrate | inserted, deleted, updated | rows/s | | postgres.dbconflictsrate | conflicts | queries/s | | postgres.dbconflictsreason_rate | tablespace, lock, snapshot, bufferpin, deadlock | queries/s | | postgres.dbdeadlocksrate | deadlocks | deadlocks/s | | postgres.dblocksheldcount | accessshare, rowshare, rowexclusive, shareupdate, share, sharerowexclusive, exclusive, accessexclusive | locks | | postgres.dblocksawaitedcount | accessshare, rowshare, rowexclusive, shareupdate, share, sharerowexclusive, exclusive, accessexclusive | locks | | postgres.dbtempfilescreatedrate | created | files/s | | postgres.dbtempfilesiorate | written | B/s | | postgres.db_size | size | B | These metrics refer to the database table. Labels: | Label | Description | |:--|:-| | database | database name | | schema | schema name | | table | table name | | parent_table | parent table name | Metrics: | Metric | Dimensions | Unit | |:|:-|:-| | postgres.tablerowsdead_ratio | dead | percentage | | postgres.tablerowscount | live, dead | rows | | postgres.tableopsrows_rate | inserted, deleted, updated | rows/s | | postgres.tableopsrowshotratio | hot | percentage | | postgres.tableopsrowshotrate | hot | rows/s | | postgres.tablecacheio_ratio | miss | percentage | | postgres.tableiorate | memory, disk | B/s | | postgres.tableindexcacheioratio | miss | percentage | | postgres.tableindexio_rate | memory, disk | B/s | | postgres.tabletoastcacheioratio | miss | percentage | | postgres.tabletoastio_rate | memory, disk | B/s | | postgres.tabletoastindexcacheio_ratio | miss | percentage | | postgres.tabletoastindexiorate | memory, disk | B/s | | postgres.tablescansrate | index, sequential | scans/s | | postgres.tablescansrows_rate | index, sequential | rows/s | | postgres.tableautovacuumsince_time | time | seconds | | postgres.tablevacuumsince_time | time | seconds | | postgres.tableautoanalyzesince_time | time | seconds | | postgres.tableanalyzesince_time | time | seconds | | postgres.tablenullcolumns | null | columns | | postgres.table_size | size | B | | postgres.tablebloatsize_perc | bloat | percentage | | postgres.tablebloatsize | bloat | B | These metrics refer to the table index. Labels: | Label | Description | |:--|:-| | database | database name | | schema | schema name | | table | table name | | parent_table | parent table name | | index | index name | Metrics: | Metric | Dimensions | Unit | |:|:-|:-| | postgres.index_size | size | B | | postgres.indexbloatsize_perc | bloat | percentage | | postgres.indexbloatsize | bloat | B | | postgres.indexusagestatus | used, unused | status | The following alerts are available: | Alert name | On metric | Description | |:|:-|:| | | postgres.connections_utilization | average total connection utilization over the last minute | | | postgres.locks_utilization | average acquired locks utilization over the last minute | | | postgres.txidexhaustionperc | percent towards TXID wraparound | | | postgres.dbcacheio_ratio | average cache hit ratio in db ${label:database} over the last minute | | | postgres.dbcacheio_ratio | average aborted transactions percentage in db ${label:database} over the last five minutes | | |

| number of deadlocks detected in db ${label:database} in the last minute | | | postgres.tablecacheio_ratio | average cache hit ratio in db ${label:database} table ${label:table} over the last minute | | | postgres.tableindexcacheioratio | average index cache hit ratio in db ${label:database} table ${label:table} over the last minute | | | postgres.tabletoastcacheioratio | average TOAST hit ratio in db ${label:database} table ${label:table} over the last minute | | | postgres.tabletoastindexcacheio_ratio | average index TOAST hit ratio in db ${label:database} table ${label:table} over the last minute | | | postgres.tablebloatsize_perc | bloat size percentage in db ${label:database} table ${label:table} | | | postgres.tableautovacuumsince_time | time elapsed since db ${label:database} table ${label:table} was vacuumed by the autovacuum daemon | | | postgres.tableautoanalyzesince_time | time elapsed since db ${label:database} table ${label:table} was analyzed by the autovacuum daemon | | | postgres.indexbloatsize_perc | bloat size percentage in db ${label:database} table ${label:table} index ${label:index} | Create a user with granted `pg_monitor` or `pgreadall_stat` . To create the `netdata` user with these permissions, execute the following in the psql session, as a user with CREATEROLE privileges: ```postgresql CREATE USER netdata; GRANT pg_monitor TO netdata; ``` After creating the new user, restart the Netdata agent with `sudo systemctl restart netdata`, or the for your system. The configuration file name for this integration is `go.d/postgres.conf`. You can edit the configuration file using the `edit-config` script from the Netdata . ```bash cd /etc/netdata 2>/dev/null || cd /opt/netdata/etc/netdata sudo ./edit-config go.d/postgres.conf ``` The following options can be defined globally: updateevery, autodetectionretry. <details><summary>Config options</summary> | Name | Description | Default | Required | |:-|:--|:-|:--:| | update_every | Data collection frequency. | 5 | no | | autodetection_retry | Recheck interval in seconds. Zero means no recheck will be scheduled. | 0 | no | | dsn | Postgres server DSN (Data Source Name). See . | postgres://postgres:postgres@127.0.0.1:5432/postgres | yes | | timeout | Query timeout in seconds. | 2 | no | | collectdatabasesmatching | Databases selector. Determines which database metrics will be collected. Syntax is . | | no | | maxdbtables | Maximum number of tables in the database. Table metrics will not be collected for databases that have more tables than maxdbtables. 0 means no limit. | 50 | no | | maxdbindexes | Maximum number of indexes in the database. Index metrics will not be collected for databases that have more indexes than maxdbindexes. 0 means no limit. | 250 | no | </details> An example configuration. ```yaml jobs: name: local dsn: 'postgresql://netdata@127.0.0.1:5432/postgres' ``` An example configuration. <details><summary>Config</summary> ```yaml jobs: name: local dsn: 'host=/var/run/postgresql dbname=postgres user=netdata' ``` </details> Note: When you define multiple jobs, their names must be unique. Local and remote instances. <details><summary>Config</summary> ```yaml jobs: name: local dsn: 'postgresql://netdata@127.0.0.1:5432/postgres' name: remote dsn: 'postgresql://netdata@203.0.113.0:5432/postgres' ``` </details> To troubleshoot issues with the `postgres` collector, run the `go.d.plugin` with the debug option enabled. The output should give you clues as to why the collector isn't working. Navigate to the `plugins.d` directory, usually at `/usr/libexec/netdata/plugins.d/`. If that's not the case on your system, open `netdata.conf` and look for the `plugins` setting under `[directories]`. ```bash cd /usr/libexec/netdata/plugins.d/ ``` Switch to the `netdata` user. ```bash sudo -u netdata -s ``` Run the `go.d.plugin` to debug the collector: ```bash ./go.d.plugin -d -m postgres ```