As part of integrating PostgreSQL into our production environment, we're working on monitoring software, to provide the same kinds of status reporting and alerts we have implemented for our outgoing commercial database product. One of the things we show on our "big board" is impending failure conditions, so that they can be resolved before actual failure occurs. One key component of this is free space monitoring. Since PostgreSQL uses available free disk space from the operating system, we needed methods to query this through the database. (We looked at getting it directly from the OS, but there are many reasons it makes more sense to go through functions in the database to get it.)
Peter Brant, a consultant working with us, has written code which is working for this under both Linux and Windows. I've been trying to package it up in PostgreSQL standard format for submission to the community, but I'm not sure how to handle a few things. For Linux, he used statvfs. There doesn't seem to be anything in mingw to support these functions, so he used methods declared in windows.h, which compile fine under mingw gcc and run fine on our Windows systems. My concern is that he has about 100 lines of code which differ between the Linux and Windows versions, which exceeds anything I've seen in current PostgreSQL #if statements in my code browsing. (Not that I've looked at every line, of course.) So, my questions: (1) Did I miss something regarding mingw support for statvfs? (2) If not, is it acceptable for a source file to contain that much #if code for Windows? I should probably also ask a tertiary question. His implementation reports space in 1K increments though int values. This effectively limits the maximum space which will be handled to 2 TB, which I'm told would be enough to cover our organization for the next ten years, but I suspect that the PostgreSQL community would prefer to see this handled a different way. (3) What data type should be used to report total space and free space for each volume? Thanks in advance for your responses. -Kevin P.S. To make it a bit more concrete, an example of the usage of these methods, against a local instance on my workstation, is attached.
fsutil-sample.txt
Description: Binary data
---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings