1

In the official documentation (http://www.postgresql.org/docs/9.1/static/datatype-character.html), it states text field is variable unlimited length.

I wonder what is the default size of this field (or minimum size of the field)?

1

2 Answers 2

4

The default minimum size of a text column (representing a NULL value) depends on the rest of the row. In most cases it is absolutely free, if the NULL bitmap has room for another bit.

More about calculating the effective row size:

1

By default such a column will be NULL (essentially zero-length, though remember there is a difference between a zero-length string and a NULL) unless you specify a default constraint in the table definition, and it will grow as needed when you insert data.

If you are asking how much space it takes on disk then this will never be completely zero of course, but there are few times when the minimum size is truly significant (if you are storing millions of rows with very short or mostly NULL text fields it might be). Assuming postgres' storage engine uses a structure not dissimilar to MSSQL then if they are stored off-page (small values are likely to be stored in-page) there will be a page reference (8 bytes?) to find the start of the string - so you might consider that, plus space in NULL bitmap and any other flags such as in-or-off-page, as the minimum footprint of such a type.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.