4

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?

javiertxu18
  • 207
  • 1
  • 9

2 Answers2

11

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

SELECT sum(pg_column_size(column)) FROM yourtable
Jim Jones
  • 18,404
  • 3
  • 35
  • 44
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.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263