Skip to content

Record table only size bytes as well in addition to the total size bytes #1149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Sticksman
Copy link
Contributor

pg_total_relation_size gets the size of the relation + indexes and toast, however we need to know just the size of the table itself. You can get this info from pg_table_size. Should be safe to add, this function was added back in 2010.

@Sticksman Sticksman force-pushed the only-table-size-bytes branch from 96099cb to 4bb84e9 Compare April 9, 2025 16:53
Comment on lines +189 to +190
pg_total_relation_size(relid) as total_size,
pg_table_size(relid) as table_only_size
Copy link
Contributor

@SuperQ SuperQ Apr 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I wonder if we should refactor this.

From the docs.

pg_total_relation_size accepts the OID or name of a table or toast table, and returns the total on-disk space used for that table, including all associated indexes. This function is equivalent to pg_table_size + pg_indexes_size.

Instead of exposing the pg_total_relation_size, we expose the two underlying metrics and let the users sum up the values themselves.

Suggested change
pg_total_relation_size(relid) as total_size,
pg_table_size(relid) as table_only_size
pg_indexes_size(relid) as indexes_size,
pg_table_size(relid) as table_size

@@ -156,6 +156,12 @@ var (
[]string{"datname", "schemaname", "relname"},
prometheus.Labels{},
)
statUserTablesOnlySize = prometheus.NewDesc(
prometheus.BuildFQName(namespace, userTableSubsystem, "only_size_bytes"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
prometheus.BuildFQName(namespace, userTableSubsystem, "only_size_bytes"),
prometheus.BuildFQName(namespace, userTableSubsystem, "table_size_bytes"),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants