SteveGuest

Wondering if there is some function of good method of estimating how much space a live table with varying types, and a varying number of rows will take once you save it.

Is there a way to determine how much memory a table or object is currently using?

So we can get an idea of what it’s size will be when written to disk.

-22! can be used to get the size of a table in memory, which will be very close to the on-disk space needed:

q)-22!([] a:til 1000)

8031

q)-22!([] a:til 2000)

16031

q)`:/temp/a set ([] a:til 2000) / save to file

`:/temp/a

/ hcount returns size of file on disk

q)hcount `:/temp/a

16025

For the larger question of estimating database requirements:

Notice in the data types table there’s a size column:

http://www.timestored.com/kdb-guides/kdb-reference-card

To estimate storage requirements:

Design your tables and what columns they contain.

Then for each table:

1. Multiply the size in bytes for each type to get the number of bytes needed per row.

2. Estimate the number of rows you will have now? 1 year from now? 2 years from now? As you want to be careful not just of the data size now but of of data growth rates.

3. Multiply the estimated size of a row by the number of rows forecast. To get the space requirements for that one table.

4. Total the values of all tables (and multiply by 1.5 for safety ðŸ™‚