> For the complete documentation index, see [llms.txt](https://docs.groundcover.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.groundcover.com/collect-data/data-sources/postgresql-database-monitoring/postgresql-health-metrics.md). Agents can also search and read this documentation through its [MCP server](https://docs.groundcover.com/~gitbook/mcp).

# PostgreSQL Health Metrics Reference

Exported PostgreSQL health metrics, grouped by source, with types, labels, and interpretation.

Use this reference with [PostgreSQL Database Monitoring](https://docs.groundcover.com/collect-data/data-sources/postgresql-database-monitoring.md) for prerequisites, permissions, configuration, and troubleshooting.

Amazon Aurora PostgreSQL writers and read replicas are supported. Enabled, applicable queries are attempted on each scrape; known Aurora restrictions produce warning events without failing the scrape. Metrics from supported queries continue collecting. See [Aurora PostgreSQL limitations](https://docs.groundcover.com/collect-data/data-sources/postgresql-database-monitoring.md#aurora-postgresql-limitations) for affected queries, metric availability, and diagnostic events.

Every suffix below is prefixed with `groundcover_db_pg_`. For example, `connections` is exported as `groundcover_db_pg_connections`. Metrics include `server_address`, `server_port`, integration labels such as `gc_integration_name`, and configured extra labels. Group-specific labels are described below; avoid extra labels that overwrite these dimensions.

Counters are raw cumulative database counters: use `rate()` or `increase()` to measure activity over time and handle resets. Gauges describe the current observation. A missing series can mean a disabled group, missing capability/permission, filtering, top-N selection, or an empty source. It does not imply zero. See [collection diagnostics](https://docs.groundcover.com/collect-data/monitor-data-sources-integrations.md#database-monitoring-diagnostics).

## Connections

`pg_stat_activity` and `max_connections`; labels: `db_namespace` and `state`. Waits of type Client, Activity, and Timeout retain the session-state bucket.

| Metric suffix     | Type / unit        | Meaning and additional labels                                                       |
| ----------------- | ------------------ | ----------------------------------------------------------------------------------- |
| `connections`     | Gauge; connections | Current connections; PostgreSQL excludes the collector application from this count. |
| `max_connections` | Gauge; connections | Configured connection limit.                                                        |

## Replication

pg\_stat\_replication and pg\_replication\_slots; primary only. Labels include replica, replication\_slot, and active. No replica/slot rows means no corresponding series.

| Metric suffix                     | Type / unit            | Meaning and additional labels                                                            |
| --------------------------------- | ---------------------- | ---------------------------------------------------------------------------------------- |
| `replication_lag_seconds`         | Gauge; seconds         | Write, flush, or replay lag reported for a replica. `phase`: `write`, `flush`, `replay`. |
| `replication_lag_bytes`           | Gauge; bytes           | Current WAL position minus the replica replay position.                                  |
| `replication_slot_retained_bytes` | Gauge; bytes           | WAL bytes retained behind a slot restart position.                                       |
| `replication_slot_xmin_age`       | Gauge; transaction IDs | Transaction ID age of the slot xmin; omitted when unavailable.                           |

## Standby

Recovery-only queries using replay functions and pg\_stat\_wal\_receiver. Receiver details require immediately usable pg\_monitor privileges.

| Metric suffix                      | Type / unit        | Meaning and additional labels                                                                                                     |
| ---------------------------------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------- |
| `replication_replay_lag_seconds`   | Gauge; seconds     | Time since the last replayed transaction; zero when receive and replay positions match. Omitted before a replay timestamp exists. |
| `wal_receiver_connected`           | Gauge; 0 or 1      | 1 when a WAL receiver is streaming, otherwise 0.                                                                                  |
| `wal_receiver_message_age_seconds` | Gauge; seconds     | Age of the last received or sent receiver message. `kind`: `receipt`, `send`.                                                     |
| `wal_receiver_timeline_id`         | Gauge; timeline ID | Timeline reported by the streaming WAL receiver.                                                                                  |

## Database stats

pg\_stat\_database; db\_namespace identifies the database. Timing, checksum, and session fields depend on settings and server capabilities.

| Metric suffix               | Type / unit           | Meaning and additional labels                                                                                         |
| --------------------------- | --------------------- | --------------------------------------------------------------------------------------------------------------------- |
| `deadlocks_total`           | Counter; deadlocks    | Detected deadlocks.                                                                                                   |
| `transactions_total`        | Counter; transactions | Committed or rolled-back transactions. `outcome`: `commit`, `rollback`.                                               |
| `blocks_total`              | Counter; blocks       | Database blocks read from storage or found in the PostgreSQL buffer cache. `op`: `hit`, `read`.                       |
| `rows_total`                | Counter; rows         | Rows returned, fetched, inserted, updated, or deleted. `op`: `returned`, `fetched`, `inserted`, `updated`, `deleted`. |
| `temp_files_total`          | Counter; files        | Temporary files created.                                                                                              |
| `temp_bytes_total`          | Counter; bytes        | Bytes written to temporary files.                                                                                     |
| `checksum_failures_total`   | Counter; failures     | Detected checksum failures; omitted when checksum statistics are unavailable.                                         |
| `checksums_enabled`         | Gauge; 0 or 1         | 1 when the checksum-failure statistic is available, otherwise 0.                                                      |
| `io_seconds_total`          | Counter; seconds      | Database block read/write time; requires track\_io\_timing. `op`: `read`, `write`.                                    |
| `sessions_total`            | Counter; sessions     | Sessions established.                                                                                                 |
| `sessions_terminated_total` | Counter; sessions     | Sessions terminated by abandonment, fatal error, or termination. `reason`: `abandoned`, `fatal`, `killed`.            |
| `session_seconds_total`     | Counter; seconds      | Total, active, or idle-in-transaction session time. `kind`: `total`, `active`, `idle_in_transaction`.                 |

## Transaction wraparound

pg\_database; db\_namespace identifies the database.

| Metric suffix               | Type / unit  | Meaning and additional labels                                                                                                         |
| --------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| `wraparound_headroom_ratio` | Gauge; ratio | 1 minus age(datfrozenxid) divided by 2147483648. Lower values mean less transaction ID headroom; this is not an autovacuum threshold. |

## Database size

pg\_database\_size; db\_namespace identifies each non-template, non-excluded database.

| Metric suffix         | Type / unit  | Meaning and additional labels |
| --------------------- | ------------ | ----------------------------- |
| `database_size_bytes` | Gauge; bytes | Total database size on disk.  |

## Conflicts

pg\_stat\_database\_conflicts; db\_namespace identifies the database.

| Metric suffix              | Type / unit        | Meaning and additional labels                                                                                                                       |
| -------------------------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| `recovery_conflicts_total` | Counter; conflicts | Recovery conflicts by reason. Zero counters are valid, including on a primary. `reason`: `bufferpin`, `deadlock`, `lock`, `snapshot`, `tablespace`. |

## Checkpoints

pg\_stat\_checkpointer and/or pg\_stat\_bgwriter, selected from server capabilities. Backend write/fsync counters are absent when their source columns are unavailable.

| Metric suffix                     | Type / unit          | Meaning and additional labels                                                                                                      |
| --------------------------------- | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `checkpoints_total`               | Counter; checkpoints | Timed or requested checkpoints. `kind`: `timed`, `requested`.                                                                      |
| `checkpoint_seconds_total`        | Counter; seconds     | Time spent writing or syncing checkpoints. `op`: `write`, `sync`.                                                                  |
| `buffers_written_total`           | Counter; buffers     | Buffers written by the checkpointer, background writer, or backends, where exposed. `source`: `checkpoint`, `bgwriter`, `backend`. |
| `buffers_backend_fsync_total`     | Counter; operations  | Backend fsync operations, where exposed.                                                                                           |
| `bgwriter_maxwritten_stops_total` | Counter; stops       | Times the background writer stopped because it reached its write limit.                                                            |
| `buffers_allocated_total`         | Counter; buffers     | Buffers allocated.                                                                                                                 |

## WAL

pg\_stat\_wal, when supported. WAL I/O fields may be unavailable even when WAL generation counters are collected.

| Metric suffix            | Type / unit          | Meaning and additional labels                                                                                        |
| ------------------------ | -------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `wal_records_total`      | Counter; records     | WAL records generated.                                                                                               |
| `wal_bytes_total`        | Counter; bytes       | WAL bytes generated.                                                                                                 |
| `wal_fpi_total`          | Counter; images      | Full-page images generated.                                                                                          |
| `wal_buffers_full_total` | Counter; occurrences | Times WAL buffers filled.                                                                                            |
| `wal_io_total`           | Counter; operations  | WAL write or sync operations, where exposed. `op`: `write`, `sync`.                                                  |
| `wal_io_seconds_total`   | Counter; seconds     | WAL write or sync time; requires track\_wal\_io\_timing and the corresponding source columns. `op`: `write`, `sync`. |

## WAL archiver

pg\_stat\_archiver. Counters can remain zero when archiving is inactive.

| Metric suffix              | Type / unit       | Meaning and additional labels    |
| -------------------------- | ----------------- | -------------------------------- |
| `wal_archived_total`       | Counter; files    | Successfully archived WAL files. |
| `wal_archive_failed_total` | Counter; attempts | Failed WAL archival attempts.    |

## I/O

pg\_stat\_io, when supported. Labels: backend\_type, context, object, and op.

| Metric suffix         | Type / unit         | Meaning and additional labels                                                                                                |
| --------------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `io_ops_total`        | Counter; operations | I/O operations by backend type, context, object, and operation. `op`: `read`, `write`, `extend`, `fsync`, `hit`, `eviction`. |
| `io_op_seconds_total` | Counter; seconds    | I/O operation time; requires track\_io\_timing. `op`: `read`, `write`, `extend`, `fsync`.                                    |

## Instance

Server start time, pg\_control\_checkpoint(), WAL position functions, and pg\_ls\_waldir(). Control-data/filesystem queries require access to those functions.

| Metric suffix                 | Type / unit        | Meaning and additional labels                           |
| ----------------------------- | ------------------ | ------------------------------------------------------- |
| `uptime_seconds`              | Gauge; seconds     | Time since PostgreSQL started.                          |
| `checkpoint_delay_seconds`    | Gauge; seconds     | Time since the checkpoint recorded in control data.     |
| `checkpoint_delay_bytes`      | Gauge; bytes       | WAL distance from the checkpoint position.              |
| `redo_delay_bytes`            | Gauge; bytes       | WAL distance from the checkpoint redo position.         |
| `timeline_id`                 | Gauge; timeline ID | Timeline in checkpoint control data.                    |
| `wal_files`                   | Gauge; files       | Number of files returned by pg\_ls\_waldir().           |
| `wal_dir_bytes`               | Gauge; bytes       | Combined size of files returned by pg\_ls\_waldir().    |
| `wal_oldest_file_age_seconds` | Gauge; seconds     | Age of the oldest WAL-directory file modification time. |

## Locks

pg\_locks, pg\_database, and pg\_stat\_activity; requires immediately usable pg\_monitor. Labels include db\_namespace, mode, and granted.

| Metric suffix                          | Type / unit    | Meaning and additional labels                                                                                                                                              |
| -------------------------------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `locks`                                | Gauge; locks   | Locks by mode and granted state. Missing observed combinations are emitted as zero.                                                                                        |
| `lock_idle_in_transaction_age_seconds` | Gauge; seconds | Age of the oldest idle-in-transaction session holding an ExclusiveLock or AccessExclusiveLock other than transaction/virtual transaction locks. Empty when none qualifies. |

## Tables

pg\_stat\_user\_tables and relation-size functions in each eligible database. Labels: db\_namespace and db\_collection\_name (schema.table). Collection requires CONNECT and is bounded by the table topN.

| Metric suffix                   | Type / unit     | Meaning and additional labels                                                                                                                                                  |
| ------------------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `table_rows`                    | Gauge; rows     | Estimated live/dead tuples. `kind`: `live`, `dead`.                                                                                                                            |
| `table_scans_total`             | Counter; scans  | Sequential or index scans of the selected table. `kind`: `seq`, `idx`.                                                                                                         |
| `table_tuples_total`            | Counter; tuples | Inserted, updated, deleted, or HOT-updated tuples. `op`: `inserted`, `updated`, `deleted`, `hot_updated`.                                                                      |
| `table_size_bytes`              | Gauge; bytes    | Heap, total relation, or combined index size for the table. `kind`: `heap`, `total`, `indexes`.                                                                                |
| `table_last_vacuum_age_seconds` | Gauge; seconds  | Age since vacuum, autovacuum, analyze, or autoanalyze. Unknown timestamps omit that series; they do not become zero. `kind`: `vacuum`, `autovacuum`, `analyze`, `autoanalyze`. |
| `table_vacuum_total`            | Counter; runs   | Vacuum, autovacuum, analyze, or autoanalyze runs. `kind`: `vacuum`, `autovacuum`, `analyze`, `autoanalyze`.                                                                    |

## Indexes

pg\_stat\_user\_indexes, pg\_class, and pg\_index in each eligible database. Labels: db\_namespace, db\_collection\_name (schema.table), and index; index\_info also has unique, valid, and primary. Independently bounded by index topN.

| Metric suffix       | Type / unit       | Meaning and additional labels                                                                                                     |
| ------------------- | ----------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `index_scans_total` | Counter; scans    | Scans initiated on the selected index.                                                                                            |
| `index_size_bytes`  | Gauge; bytes      | Index size on disk.                                                                                                               |
| `index_info`        | Gauge; constant 1 | Constant 1 with unique, valid, and primary metadata labels. Join with index statistics using database, table, and index identity. |

## Autovacuum

Instance settings and pg\_stat\_activity. The running-worker series requires immediately usable pg\_monitor; settings collection is independent of that worker query.

| Metric suffix        | Type / unit    | Meaning and additional labels                                                                                              |
| -------------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------- |
| `autovacuum_workers` | Gauge; workers | Configured maximum or currently running autovacuum workers. Manual VACUUM sessions are excluded. `kind`: `max`, `running`. |
| `autovacuum_enabled` | Gauge; 0 or 1  | 1 when the instance autovacuum setting is on, otherwise 0. This does not describe table-specific overrides.                |

## Additional instance metrics

| Full metric name                             | Type    | Meaning                                                                                                                                                              |
| -------------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `groundcover_db_pg_is_in_recovery`           | Gauge   | 1 on a standby, 0 on a primary; emitted when Replication or Standby is enabled.                                                                                      |
| `groundcover_db_pg_statements_evicted_total` | Counter | pg\_stat\_statements\_info.dealloc; emitted by statement collection when the info view is available. Increasing values indicate statement entries are being evicted. |

## Query examples

Replace `<integration-name>` with the integration name. Choose a rate window spanning several scrapes.

Transaction rate:

```promql
sum by (db_namespace, outcome) (
  rate(groundcover_db_pg_transactions_total{gc_integration_name="<integration-name>"}[5m])
)
```

Buffer-cache hit ratio, derived from counters (not an independently exported metric). A database with no block activity has an undefined ratio:

```promql
sum by (db_namespace) (rate(groundcover_db_pg_blocks_total{gc_integration_name="<integration-name>", op="hit"}[5m]))
/
sum by (db_namespace) (rate(groundcover_db_pg_blocks_total{gc_integration_name="<integration-name>"}[5m]))
```

Estimated dead tuples for the selected tables:

```promql
groundcover_db_pg_table_rows{gc_integration_name="<integration-name>", kind="dead"}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.groundcover.com/collect-data/data-sources/postgresql-database-monitoring/postgresql-health-metrics.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
