how to calculate the size of each table of a database?

Your best source of information, IMHO, would be the database analysis which produces such a report. You can run it off- or online using the proutil command line utility and re-direct the output into a file. Plus the report will contain tons of other useful information like mean records per block, etc.

Code:
proutil  -C dbanalys >

Heavy Regards, RealHeavyDude.
 
Just saw that my code was screwed:

proutil database-name -C dbanalys > output-file.

Heavy Regards, RealHeavyDude.
 
To begin with, I don't have such code. But, I wouldn't advise to calculate such information online as it might take some time to get the numbers. At least it would mean a table scan to get the information for a given table.

Instead I would run the database analysis on a regular basis, parse it and store the relevant information in the database. Unless you have a table with an extremely high transaction load the data should be sufficient. That way the information will be readily available when you need it.

Heavy Regards, RealHeavyDude.
 
Then you should take RHD's advice, run proutil and parse the output. It isn't all that hard and it will be infinitely faster.
 
To echo Tom's question, what do you want to do with the size you are reporting on? I would caution you that it could be misinterpreted. If you just want, for example, month-to-month growth figures so you can see which tables are growing over time, then dbanalys output will give you that.

But don't expect the actual numbers to correspond to the amount of disk space used by the data in question. Depending on your structure, there could be a significant difference between the two.
 
Back
Top