9

I have a big table on my database, but it has a lot of empty fields on every column, and I´d like to know how much does every column use.

Is there any way to know how much disk space is each tables columns using?

1
  • 2
    pg_column_size()? Commented Feb 24, 2020 at 12:19

2 Answers 2

17

Try using pg_column_size(), it will return the column size in bytes:

SELECT sum(pg_column_size(column)) FROM yourtable
Sign up to request clarification or add additional context in comments.

Comments

3

As the documentation mentions, NULL values are indicated in the null bitmap of every tuple, which is always present if the table has nullable columns.

So a NULL value consumes no extra space on disk.

If you design tables with very many columns, rethink your design.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.