I need to estimate the size in GB of a table in a PostgreSQL database. I don’t have the database yet (I need the estimate for cost projection purposes).
The schema of the table will be:
- One column containing a timestamp of when the record was created
- K other columns, all float numbers
K can be anywhere between 10 and 10000.
Is there a formula to estimate how big the table will be in GB, as a function of K and of the number of rows?
2
Answers
You could perhaps use this formula:
In PostgreSQL, the size of timestamp data type is generally 8 bytes. Float is 4 bytes.
This formula however does not factor in null values, padding, alignment, compression, or indexing which could increase the size.
You could also use the pg_total_relation_size function in PostgreSQL. You provide the function with the table’s name and it gives you the size of the table, including indexes and associated objects.
a tiemstamp needs 8 bytes
A real 4 Bytes
So you have 8+ K * 4 bytes of raw data
lets say for 10
which ar 8.400000000000001e-8 Giagbyte, kow you need to estmate the rows you have prer month or year and multiple it