PostgreSQL: Column Disk usage

Viewed 957

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?

2 Answers

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

SELECT sum(pg_column_size(column)) FROM yourtable

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.

Related