Skip to main content

postgres_ai monitoring reference documentation

Metrics

Common labels

Most metrics include these standard labels:

  • cluster - Cluster identifier (e.g., "default")
  • datname - Database name being monitored
  • env - Environment (e.g., "production")
  • instance - pgwatch instance identifier
  • job - Prometheus job name
  • node_name - Database node name
  • sink_type - Metrics sink type (e.g., "prometheus")
  • sys_id - System identifier

Metric-specific labels

Additional labels are available for specific metric types:

  • Query metrics (pg_stat_statements): queryid, user
  • Table metrics (table_stats, pg_stat_user_tables): schema, table_name, table_full_name, table_size_cardinality_mb
  • Index metrics (pg_stat_user_indexes): schemaname, relname, indexrelname
  • Lock metrics (locks_mode): lockmode
  • Wait events (wait_events): wait_event, wait_event_type
  • Replication metrics: application_name, client_info, usename
  • Settings metrics: setting_name, setting_value, unit, category, vartype

Background writer metrics (bgwriter, checkpointer)

Collected every 30 seconds

MetricDescriptionUnits
bgwriter_checkpoints_timedNumber of scheduled checkpoints performed-
bgwriter_checkpoints_reqNumber of requested checkpoints performed-
bgwriter_checkpoint_write_timeTime spent writing checkpoint data to diskMilliseconds
bgwriter_checkpoint_sync_timeTime spent syncing checkpoint data to diskMilliseconds
bgwriter_buffers_checkpointBuffers written during checkpoints-
bgwriter_buffers_cleanBuffers cleaned by background writer-
bgwriter_maxwritten_cleanTimes background writer stopped due to max write limit-
bgwriter_buffers_backendBuffers written directly by backends-
bgwriter_buffers_backend_fsyncTimes backends performed direct fsync-
bgwriter_buffers_allocBuffers allocated-
bgwriter_last_reset_sSeconds since bgwriter stats resetSeconds
checkpointer_num_timedNumber of timed checkpoints performed-
checkpointer_num_requestedNumber of requested checkpoints performed-
checkpointer_restartpoints_timedNumber of timed restart points performed-
checkpointer_restartpoints_reqNumber of requested restart points performed-
checkpointer_restartpoints_doneNumber of restart points completed-
checkpointer_write_timeTime spent writing checkpoint dataMilliseconds
checkpointer_sync_timeTime spent syncing checkpoint dataMilliseconds
checkpointer_buffers_writtenNumber of buffers written by checkpointer-
checkpointer_last_reset_sSeconds since stats resetSeconds

Database statistics (db_stats, db_size, pg_stat_activity)

Collected every 15-30 seconds

MetricDescriptionUnits
db_stats_numbackendsNumber of active connections to database-
db_stats_xact_commitTransactions committed-
db_stats_xact_rollbackTransactions rolled back-
db_stats_blks_readDisk blocks read-
db_stats_blks_hitBuffer cache hits-
db_stats_tup_returnedRows returned by queries-
db_stats_tup_fetchedRows fetched by queries-
db_stats_tup_insertedRows inserted-
db_stats_tup_updatedRows updated-
db_stats_tup_deletedRows deleted-
db_stats_conflictsRecovery conflicts-
db_stats_temp_filesTemporary files created-
db_stats_temp_bytesTemporary file bytes writtenBytes
db_stats_deadlocksDeadlocks detected-
db_stats_blk_read_timeTime spent reading data file blocksMilliseconds
db_stats_blk_write_timeTime spent writing data file blocksMilliseconds
db_stats_postmaster_uptime_sPostgres server uptimeSeconds
db_stats_backup_duration_sCurrent backup durationSeconds
db_stats_in_recovery_intWhether instance is in recovery modeBoolean (0/1)
db_stats_invalid_indexesCount of invalid indexes-
db_stats_session_timeTime spent in database sessionsMilliseconds
db_stats_active_timeTime spent executing queriesMilliseconds
db_stats_idle_in_transaction_timeTime spent idle in transactionsMilliseconds
db_stats_sessionsTotal number of sessions-
db_stats_sessions_abandonedSessions abandoned-
db_stats_sessions_fatalSessions ended fatally-
db_stats_sessions_killedSessions killed-
db_size_size_bDatabase size in bytesBytes
db_size_catalog_size_bCatalog schema size in bytesBytes
pg_stat_activity_countCount of sessions by state-
pg_stat_activity_max_tx_durationMaximum transaction durationSeconds

Query performance (pg_stat_statements)

Collected every 30 seconds Additional Labels: queryid (query identifier), user (database user)

MetricDescriptionUnits
pg_stat_statements_callsNumber of times query executed-
pg_stat_statements_plans_totalNumber of times query planned-
pg_stat_statements_exec_time_totalTotal execution timeMilliseconds
pg_stat_statements_plan_time_totalTotal planning timeMilliseconds
pg_stat_statements_rowsTotal rows returned/affected-
pg_stat_statements_shared_bytes_hit_totalShared buffer cache hitsBytes
pg_stat_statements_shared_bytes_read_totalShared buffer reads from diskBytes
pg_stat_statements_shared_bytes_dirtied_totalShared buffer blocks dirtiedBytes
pg_stat_statements_shared_bytes_written_totalShared buffer blocks writtenBytes
pg_stat_statements_block_read_totalTime spent reading blocksMilliseconds
pg_stat_statements_block_write_totalTime spent writing blocksMilliseconds
pg_stat_statements_wal_recordsWAL records generated-
pg_stat_statements_wal_fpiWAL full page images generated-
pg_stat_statements_wal_bytesWAL bytes generatedBytes
pg_stat_statements_temp_bytes_readTemporary file bytes readBytes
pg_stat_statements_temp_bytes_writtenTemporary file bytes writtenBytes

Lock statistics (locks_mode)

Collected every 30 seconds Additional Labels: lockmode (lock type: AccessShareLock, RowExclusiveLock, etc.)

MetricDescriptionUnits
locks_mode_countNumber of locks held by mode type-

Wait events (wait_events)

Collected every 15 seconds Additional Labels: wait_event (specific wait event), wait_event_type (wait category), query_id (associated query)

MetricDescriptionUnits
wait_events_totalCount of processes experiencing wait event-

Table statistics (table_stats, pg_stat_user_tables)

Collected every 30 seconds Additional Labels: schema (table schema), table_name (table name), table_full_name (schema.table), table_size_cardinality_mb (size category)

MetricDescriptionUnits
table_stats_table_size_bTable size in bytesBytes
table_stats_total_relation_size_bTotal relation size including indexesBytes
table_stats_toast_size_bTOAST table sizeBytes
table_stats_seq_scanSequential scans performed-
table_stats_seq_tup_readRows read by sequential scans-
table_stats_idx_scanIndex scans performed-
table_stats_idx_tup_fetchRows fetched by index scans-
table_stats_n_tup_insRows inserted-
table_stats_n_tup_updRows updated-
table_stats_n_tup_delRows deleted-
table_stats_n_tup_hot_updHOT updates performed-
table_stats_n_live_tupEstimated live rows-
table_stats_n_dead_tupEstimated dead rows-
table_stats_vacuum_countManual vacuums performed-
table_stats_autovacuum_countAutovacuums performed-
table_stats_analyze_countManual analyzes performed-
table_stats_autoanalyze_countAutoanalyzes performed-
table_stats_tx_freeze_ageTransaction freeze age-
table_stats_is_part_rootWhether table is a partition rootBoolean (0/1)
table_stats_last_seq_scan_sSeconds since last sequential scanSeconds
table_stats_no_autovacuumWhether autovacuum is disabledBoolean (0/1)
table_stats_seconds_since_last_analyzeSeconds since last analyzeSeconds
table_stats_seconds_since_last_vacuumSeconds since last vacuumSeconds

Index statistics (pg_stat_user_indexes)

Collected every 30 seconds Additional Labels: schemaname (schema name), relname (table name), indexrelname (index name)

MetricDescriptionUnits
pg_stat_user_indexes_idx_scanIndex scans performed-
pg_stat_user_indexes_idx_tup_readIndex entries returned-
pg_stat_user_indexes_idx_tup_fetchTable rows fetched via index-

WAL and replication metrics (wal, replication, replication_slots, pg_stat_replication, pg_stat_wal_receiver, pg_archiver, archive_lag, pg_xlog_position)

Collected every 15-30 seconds

MetricDescriptionUnits
wal_xlog_location_bCurrent WAL locationBytes
wal_in_recovery_intWhether instance is in recovery modeBoolean (0/1)
wal_postmaster_uptime_sPostgres server uptimeSeconds
wal_timelineCurrent timeline ID-
replication_sent_lag_bReplication sent lagBytes
replication_write_lag_bReplication write lagBytes
replication_flush_lag_bReplication flush lagBytes
replication_replay_lag_bReplication replay lagBytes
replication_write_lag_msReplication write lagMilliseconds
replication_flush_lag_msReplication flush lagMilliseconds
replication_replay_lag_msReplication replay lagMilliseconds
archive_lag_current_lsn_numericCurrent LSN as numeric value-
archive_lag_archived_wal_finish_lsn_numericArchived WAL finish LSN as numeric-
archive_lag_wal_files_behindNumber of WAL files behind archive-
archive_lag_seconds_since_archiveSeconds since last archiveSeconds
archive_lag_archived_countTotal archived WAL files-
archive_lag_failed_countFailed archive attempts-
pg_archiver_pending_wal_countNumber of WAL files pending archive-

Bloat analysis metrics (pg_table_bloat, pg_btree_bloat, unused_indexes, rarely_used_indexes, redundant_indexes, pg_invalid_indexes)

Collected every 2-3 hours

MetricDescriptionUnits
pg_table_bloat_real_size_mibActual size of table/indexMegabytes
pg_table_bloat_extra_sizeExtra space due to bloatBytes
pg_table_bloat_extra_pctPercentage of space wastedPercent
pg_table_bloat_bloat_sizeEstimated bloat sizeBytes
pg_table_bloat_bloat_pctEstimated bloat percentagePercent
pg_btree_bloat_real_size_mibActual index sizeMegabytes
pg_btree_bloat_extra_sizeExtra space due to index bloatBytes
pg_btree_bloat_extra_pctPercentage of index space wastedPercent
pg_btree_bloat_bloat_sizeEstimated index bloat sizeBytes
pg_btree_bloat_bloat_pctEstimated index bloat percentagePercent
pg_btree_bloat_fillfactorIndex fill factor-
pg_btree_bloat_is_naWhether bloat calculation is not availableBoolean (0/1)

Transaction and process metrics (pg_blocked, pg_long_running_transactions, pg_stuck_idle_in_transaction, pg_txid, pg_database_wraparound, pg_vacuum_progress, pg_total_relation_size)

Collected every 30 seconds

MetricDescriptionUnits
pg_blocked_queriesNumber of blocked queries-
pg_long_running_transactions_transactionsNumber of long-running transactions-
pg_long_running_transactions_age_in_secondsAge of longest transactionSeconds
pg_database_wraparound_age_datfrozenxidAge of database frozen transaction ID-
pg_database_wraparound_age_datminmxidAge of database minimum multixact ID-
pg_stuck_idle_in_transaction_queriesNumber of stuck idle-in-transaction queries-
pg_txid_currentCurrent transaction ID-
pg_txid_xminMinimum transaction ID in snapshot-
pg_txid_xmin_ageAge of minimum transaction ID-
pg_total_relation_size_bytesTotal relation size including indexesBytes

Configuration settings (settings)

Collected every 5 minutes Additional Labels: setting_name (parameter name), setting_value (parameter value), unit (value unit), category (setting category), vartype (variable type)

MetricDescriptionUnits
settings_numeric_valueNumeric value of configuration setting-
settings_is_defaultWhether setting is at default valueBoolean (0/1)
settings_configuredWhether setting is configuredBoolean (0/1)