Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL: Column Disk usage

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?

like image 206
javiertxu18 Avatar asked May 11 '26 02:05

javiertxu18


2 Answers

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

SELECT sum(pg_column_size(column)) FROM yourtable
like image 123
Jim Jones Avatar answered May 13 '26 16:05

Jim Jones


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.

like image 34
Laurenz Albe Avatar answered May 13 '26 17:05

Laurenz Albe