Thread
-
Re: Available disk space per tablespace
Zsolt Parragi <zsolt.parragi@percona.com> — 2026-05-06T22:59:21Z
Hello! #ifdef WIN32 + if (! GetDiskFreeSpaceEx(tblspcPath, &lpFreeBytesAvailable, NULL, NULL)) + elog(ERROR, "GetDiskFreeSpaceEx failed: error code %lu", GetLastError()); + + return lpFreeBytesAvailable.QuadPart; /* ULONGLONG part of ULARGE_INTEGER */ +#else Shouldn't this use proper error codes similar to the else branch, and also _dosmaperr? There's also a behavior difference here compared to Linux, it returns -1 on ENOENT, the Windows version errors out on the matching condition. + " wHERE db.datname OPERATOR(pg_catalog.=) pg_catalog.current_database()) dbsub\n"); typo, should be WHERE + (errcode_for_file_access(), + errmsg("could not statvfs directory \"%s\": %m", tblspcPath))); Is this error message user friendly? Wouldn't be something like "could not get free disk space for directory" be better? + Returns the available disk space in the tablespace with the + specified name or OID. Does the tablespace have a disk space? Maybe "returns the space on the filesystem hosting the tablespace"? + return fst.f_bavail * fst.f_frsize; /* available blocks times fragment size */ > There is some code that does int width expansion, but I believe we > don't need that since the `fst.f_bavail * fst.f_frsize` multiplication > takes care of converting that to int64 (if it wasn't already 64bits > before). I don't think this is the case, we first multiply and then cast. Multiplication still happens with 32 bit types. Relevant parts on Godbolt: https://godbolt.org/z/7dj7crf6K