Re: Windows pg_basebackup unable to create >2GB pg_wal.tar tarballs ("could not close file: Invalid argument" when creating pg_wal.tar of size ~ 2^31 bytes)
Davinder Singh <davinder.singh@enterprisedb.com>
From: Davinder Singh <davinder.singh@enterprisedb.com>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: Jakub Wartak <jakub.wartak@enterprisedb.com>, PostgreSQL Hackers <pgsql-hackers@postgresql.org>,
Dilip Kumar <dilip.kumar@enterprisedb.com>
Date: 2024-11-27T12:12:26Z
Lists: pgsql-hackers
Attachments
- v2_0001-Bugfix-Windows-pg_basebackup-ability-to-create-2GB-p.patch (application/octet-stream) patch v2-0001
Hi,
On Sat, Nov 23, 2024 at 5:14 AM Thomas Munro <thomas.munro@gmail.com> wrote:
> On Fri, Nov 22, 2024 at 10:55 PM Jakub Wartak
> <jakub.wartak@enterprisedb.com> wrote:
> > but with attached _lseeki64 dirty patch I've got success and resulting
> tarball greater than 2^31 too:
>
>
> For ftruncate(), though you didn't see a problem with that, Jacob is
> quite right that it must be able to corrupt stuff, and I retract that
> replacement code I showed earlier, it's not really OK to move the file
> position around. I would like to use _s_chsize() instead, but it
> arrived in msvcr80.dll so I don't think old MinGW can use it. Here's
> a new idea (sketch code not tested):
>
> static inline int
> ftruncate(int fd, pgoff_t length)
> {
> #if defined(_UCRT) || defined(_MSC_VER)
> /* MinGW + UCRT and all supported MSVC versions have this. */
> errno = _s_chsize(fd, length);
> return errno == 0 ? 0 : -1;
> #else
> /* MinGW + ancient msvcrt.dll has only _chsize, limited by off_t
> (long). */
> if (length > LONG_MAX)
> {
> /* A clear error is better than silent corruption. */
> errno = EFBIG;
> return - 1;
> }
> return _chsize(fd, length);
> #endif
> }
>
With the earlier patch, there were some compilation issues on other
platforms, I have modified the patch a little by using some of the changes
from the earlier patch shared by Thomas. Also, I have used the above code
to enable ftruncate() to handle pgoff_t. All the builds and tests on the CI
build <https://cirrus-ci.com/build/6351585205288960> passed except an
already existing build failure in the mingw_cross compiler (not related to
the patch).
--
Regards,
Davinder.
Commits
-
Fix off_t overflow in pg_basebackup on Windows.
- bd0564f61d37 13.19 landed
- 8f40d46126a0 14.16 landed
- 6b6901a26f56 15.11 landed
- be7489662e77 16.7 landed
- faee3185aafa 17.3 landed
- 970b97eeb8f0 18.0 landed
-
Provide 64-bit ftruncate() and lseek() on Windows.
- 026762dae39d 18.0 landed
- af109e3399b6 17.3 landed
- 0bff6f1da842 16.7 landed
- 70a7a37610f7 15.11 landed
- 1636c5e56ed7 14.16 landed
- d02486cc8e0a 13.19 landed
-
Require ucrt if using MinGW.
- 1758d4244616 18.0 cited