Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Use pg_table_size() when collecting size of tables. Previously used p…
Browse files Browse the repository at this point in the history
…g_relation_size() doesn't account size of all forks and TOASTed data, and table size might seemed incomplete.
  • Loading branch information
lesovsky committed Jun 23, 2021
1 parent 7045716 commit 94a24c0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/collector/postgres_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (
"n_mod_since_analyze, extract('epoch' from age(now(), greatest(last_vacuum, last_autovacuum))) as last_vacuum_seconds, " +
"extract('epoch' from age(now(), greatest(last_analyze, last_autoanalyze))) as last_analyze_seconds, " +
"vacuum_count, autovacuum_count, analyze_count, autoanalyze_count, heap_blks_read, heap_blks_hit, idx_blks_read, " +
"idx_blks_hit, toast_blks_read, toast_blks_hit, tidx_blks_read, tidx_blks_hit, pg_relation_size(s1.relid) AS size_bytes " +
"idx_blks_hit, toast_blks_read, toast_blks_hit, tidx_blks_read, tidx_blks_hit, pg_table_size(s1.relid) AS size_bytes " +
"FROM pg_stat_user_tables s1 JOIN pg_statio_user_tables s2 USING (schemaname, relname) " +
"WHERE NOT EXISTS (SELECT 1 FROM pg_locks WHERE relation = s1.relid AND mode = 'AccessExclusiveLock' AND granted)"
)
Expand Down Expand Up @@ -142,7 +142,7 @@ func NewPostgresTablesCollector(constLabels labels, settings model.CollectorSett
settings.Filters,
),
sizes: newBuiltinTypedDesc(
descOpts{"postgres", "table", "size_bytes", "Total size of the table, in bytes.", 0},
descOpts{"postgres", "table", "size_bytes", "Total size of the table (including all forks and TOASTed data), in bytes.", 0},
prometheus.GaugeValue,
labels, constLabels,
settings.Filters,
Expand Down

0 comments on commit 94a24c0

Please sign in to comment.