v1-0001-WIP-increase-glibc-buffering-for-pg_restore-custo.patch
text/x-patch
Filename: v1-0001-WIP-increase-glibc-buffering-for-pg_restore-custo.patch
Type: text/x-patch
Part: 0
Patch
Format: format-patch
Series: patch v1-0001
Subject: WIP: increase glibc buffering for pg_restore custom format
| File | + | − |
|---|---|---|
| src/bin/pg_dump/pg_backup_custom.c | 9 | 0 |
From 56559e95fabbc498d7127db45992336f10a6cd93 Mon Sep 17 00:00:00 2001
From: Dimitrios Apostolou <jimis@qt.io>
Date: Tue, 21 Oct 2025 15:55:47 +0200
Subject: [PATCH v1] WIP: increase glibc buffering for pg_restore custom format
---
src/bin/pg_dump/pg_backup_custom.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/bin/pg_dump/pg_backup_custom.c b/src/bin/pg_dump/pg_backup_custom.c
index f7c3af56304..79ffac315b5 100644
--- a/src/bin/pg_dump/pg_backup_custom.c
+++ b/src/bin/pg_dump/pg_backup_custom.c
@@ -160,18 +160,22 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
ctx->hasSeek = checkSeek(AH->FH);
}
else
{
if (AH->fSpec && strcmp(AH->fSpec, "") != 0)
{
AH->FH = fopen(AH->fSpec, PG_BINARY_R);
if (!AH->FH)
pg_fatal("could not open input file \"%s\": %m", AH->fSpec);
+ void *buf = pg_malloc(1024*1024);
+ int ret = setvbuf(AH->FH, buf, _IOFBF, 1024*1024);
+ if (ret != 0)
+ pg_fatal("setvbuf failed: %m");
}
else
{
AH->FH = stdin;
if (!AH->FH)
pg_fatal("could not open input file: %m");
}
ctx->hasSeek = checkSeek(AH->FH);
@@ -808,18 +812,23 @@ _ReopenArchive(ArchiveHandle *AH)
pg_fatal("could not close archive file: %m");
#endif
AH->FH = fopen(AH->fSpec, PG_BINARY_R);
if (!AH->FH)
pg_fatal("could not open input file \"%s\": %m", AH->fSpec);
if (fseeko(AH->FH, tpos, SEEK_SET) != 0)
pg_fatal("could not set seek position in archive file: %m");
+
+ void *buf = pg_malloc(1024*1024);
+ int ret = setvbuf(AH->FH, buf, _IOFBF, 1024*1024);
+ if (ret != 0)
+ pg_fatal("setvbuf failed: %m");
}
/*
* Prepare for parallel restore.
*
* The main thing that needs to happen here is to fill in TABLE DATA and BLOBS
* TOC entries' dataLength fields with appropriate values to guide the
* ordering of restore jobs. The source of said data is format-dependent,
* as is the exact meaning of the values.
--
2.51.0