If you worked with postgresql, you may know it stores various stats in internal views. I want to get stats with some interval and store it into a binary file. I see it in the following way:
- read stats with PQexec() from libpq.
- using info about the number of rows and columns from result, allocate a 3d pointer array.
- put result to the 3d array (which is already a part of struct)
- write struct with 3d array to binary file
- go to step 1 and repeat
Next, it's possible to read this binary file, read struct in to the similar 3d array and then sort values, view and so on.
And everything looks fine, until number of rows is constant, but in postgresql there are views where number of rows are changed permanently. Thus sizes of written structs will be always different and I don't know how to properly read these structs from file (because I need to know the size of struct).
Could you advise me or propose a better way to do it?