pgsql: Avoid short seeks in pg_restore.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Avoid short seeks in pg_restore.
Date: 2025-10-21 18:10:25
Message-ID: E1vBGoT-002opd-2b@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Avoid short seeks in pg_restore.

If a data block to be skipped over is less than 4kB, just read the
data instead of using fseeko(). Experimentation shows that this
avoids useless kernel calls --- possibly quite a lot of them, at
least with current glibc --- while not incurring any extra I/O,
since libc will read 4kB at a time anyway. (There may be platforms
where the default buffer size is different from 4kB, but this
change seems unlikely to hurt in any case.)

We don't expect short data blocks to be common in the wake of
66ec01dc4 and related commits. But older pg_dump files may well
contain very short data blocks, and that will likely be a case
to be concerned with for a long time.

While here, do a little bit of other cleanup in _skipData.
Make "buflen" be size_t not int; it can't really exceed the
range of int, but comparing size_t and int variables is just
asking for trouble. Also, when we initially allocate a buffer
for reading skipped data into, make sure it's at least 4kB to
reduce the odds that we'll shortly have to realloc it bigger.

Author: Dimitrios Apostolou <jimis(at)gmx(dot)net>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/2edb7a57-b225-3b23-a680-62ba90658fec@gmx.net

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/fba60a1b107df425ec9676b8cf759830a70def03

Modified Files
--------------
src/bin/pg_dump/pg_backup_custom.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Nathan Bossart 2025-10-21 21:40:01 pgsql: Add .abi-compliance-history to back-branches.
Previous Message Nathan Bossart 2025-10-21 17:24:25 pgsql: Add reminder to create .abi-compliance-history.