I read on internet that null values take up to 1bit of space but I am unclear about empty values. Please help me in this. Thank-you in advance
-
1Does this answer your question? [How much disk-space is needed to store a NULL value using postgresql DB?](https://stackoverflow.com/questions/4229805/how-much-disk-space-is-needed-to-store-a-null-value-using-postgresql-db) – nbk Jul 12 '22 at 17:43
1 Answers
The documentation gives information about that:
All table rows are structured in the same way. There is a fixed-size header (occupying 23 bytes on most machines), followed by an optional null bitmap, an optional object ID field, and the user data. [...] The null bitmap is only present if the HEAP_HASNULL bit is set in
t_infomask
. [...] In this list of bits, a 1 bit indicates not-null, a 0 bit is a null. When the bitmap is not present, all columns are assumed not-null.
A NULL value does not take up any extra space on disk – it means that the respective bit in the null bitmap is set to 0. Only of the table row contains no NULL values at all, PostgreSQL will not save a null bitmap and you can actually save a little space.
An empty string will occupy one byte: a short varlena header that indicates that the length is 0. Beware of padding bytes because of alignment: if, for example, a timestamp
immediately follows the empty string, you could get up to 7 bytes of empty padding space, so that the timestamp
starts at an address that is a multiple of 8.

- 209,280
- 17
- 206
- 263