skip to Main Content

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


  1. You could perhaps use this formula:

    Estimated Table Size (in bytes) = (Number of Rows) * (Size of
    Timestamp Column + (K * Size of Float Column))

    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.

    Login or Signup to reply.
  2. a tiemstamp needs 8 bytes

    A real 4 Bytes

    So you have 8+ K * 4 bytes of raw data

    lets say for 10

       23   -- heaptupleheader
     +  1   -- padding or NULL bitmap
     + 40   -- 10 * ireal
     +  8   -- padding after 3rd integer
     +  8   -- timestamp
     +  0   -- no padding since tuple ends at multiple of MAXALIGN
     +  4   -- item identifier in page header
    ------
     = 84 bytes for every row
    

    which ar 8.400000000000001e-8 Giagbyte, kow you need to estmate the rows you have prer month or year and multiple it

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search