Skip to content
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

PostgreSQL: Make data length calculation more accurate #486

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

Conversation

caltong
Copy link

@caltong caltong commented Jan 2, 2024

According to my testing and PG doc below, the original data length does not include the size of TOAST, while the index length, on the contrary, includes the size of TOAST.

In this PR, I use the pg_table_size and pg_indexes_size to make data length and index length more accurate.

The TOAST management code is triggered only when a row value to be stored in a table is wider than TOAST_TUPLE_THRESHOLD bytes (normally 2 kB). The TOAST code will compress and/or move field values out-of-line until the row value is shorter than TOAST_TUPLE_TARGET bytes (also normally 2 kB, adjustable) or no more gains can be had. During an UPDATE operation, values of unchanged fields are normally preserved as-is; so an UPDATE of a row with out-of-line values incurs no TOAST costs if none of the out-of-line values change.

pg_table_size ( regclass ) → bigint. Computes the disk space used by the specified table, excluding indexes (but including its TOAST table if any, free space map, and visibility map).

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