Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v8U0K-001O05-U2 for pgsql-hackers@arkaria.postgresql.org; Tue, 14 Oct 2025 01:39:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1v8TzI-009WNr-IW for pgsql-hackers@arkaria.postgresql.org; Tue, 14 Oct 2025 01:38:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v8TzI-009WNj-2j for pgsql-hackers@lists.postgresql.org; Tue, 14 Oct 2025 01:38:05 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v8TzG-001cw4-2o for pgsql-hackers@lists.postgresql.org; Tue, 14 Oct 2025 01:38:03 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-2698e4795ebso46938715ad.0 for ; Mon, 13 Oct 2025 18:38:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1760405882; x=1761010682; darn=lists.postgresql.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=HGPOuvFqDTOiz/PTE6lDDOtiYCAT+YP4PHsPPxoaE+0=; b=a8VQ1c51y4N2wUuOdP0UkrwdNaEg3r3YEdx5/jK1s/l+UOs/Gc3XSc3ru68Z5t3cAJ vBQq+WJCv/hLvCU7d0jZMJ/9LyKdmyrQQA60kMAL+s0F9xSZqtqVjxwW0VPbLNokM8A8 r5/RNYrt7ceaQIi+0sJ/WGmfGGUEQRgithUov/rcyXMBSw0DCL5wXnwGByDecuMZkM1E d8yBxNUjzCIn5dOsl+eLG9ar0ANAe1UMPY62q9wvDo8xap5M0BgGVPG5QJzCaNehZhEo jWPpx8Na4HeYzmbZFSaT0YIA72hSHuTkGKpv3ekBG211tCk7RqGIdUAuclkXBxAuoE5I S/IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760405882; x=1761010682; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HGPOuvFqDTOiz/PTE6lDDOtiYCAT+YP4PHsPPxoaE+0=; b=i67D9k+CW2KUIvAk7J0iPNBYMjIW8gAsA4PoInw/2mBeC7v8m8Rbxu618Zdx3NlPTK X/Pnt6G9MrJmUCJesYyQ6tNwxIym/JUgxdviFIX/sU674+0mvvzigUnde/6X6NKyxxqN Mg462YvPnpS3ALgJk++T9LGSlN1UsYtyXpjxU4NSFv1M2lpgBMqDMlcUnFhVzhde+E65 O6e209g18V9pUIVhxI/yJ/cxkSn4aUUjwwy/pLZ27H9IsX5dBtWnX7agJb2FOMiiCuWq 6cO+pTmyuClKAnllcPX5c+k/IsOPzolv8FNVRfyjAeHe9Rlea3RPxWxcZUcNYnbLsoTe 2DjQ== X-Forwarded-Encrypted: i=1; AJvYcCXZMJEglxhYnc0kqwxUY+Erlg9iuWacVPFGureqXrSInFd2y4Jc3jkAje27/HrDfvLAnMWnx0gjLQ6isa/t@lists.postgresql.org X-Gm-Message-State: AOJu0YyR5gntNnMSLMiVo7vo97YRwP1aWK66erQnQ81PAjPPEBG/1lWl eplWZpSkROiF664gXbHOF6T4wZceYYxOX2iKV4zuX6l/VJqMwQ4nto7+ X-Gm-Gg: ASbGncuOxZcoe0UUH54yX/zDTaSVp8YFAHEG7p7ZkLAxgyrMplco/8ILrILUPf7SwFp R++jk2ZhqECePN/fSgSf+k+fE0Ns7DObl4umwSPQy0fHVGnvO/xexEZYNAAxT+dB+DFZT87DV2A rT17h6pdf5wjGf80xr7udXNLmXGbCXjjYa1MY9+BPwGB+5BFx+gZnwsh0kDFRYg2eFhWkENmjvG pW6ce78pjyH8DwXWzqlm8eU43uKB70Vq7sA/jMFUWMo0SSlWQh3PkTBDRhwAH/cNShijfnM4Rae TJZ3oFrjPHPpUJt6rFcUpdJc92iT0oHNq3iOP6EhKs6NCvTZoH3n/RFVUfnpeR6zB4R9tkBkBFB KA8QCkZphWR5w3MhMH9+tjST1Ih2dvgJxn2wBGXq5Onszcwhu2q+iKT3TejRRG2sIQoXSMbYQhA == X-Google-Smtp-Source: AGHT+IEq3rXSJpvwEwTo1p/vrpm2bmm1lO+0zNjAX4qjDNdnkZeVqRgTbNPCtNoyF4S87DZ4DiFpGQ== X-Received: by 2002:a17:903:4b04:b0:274:746c:b09 with SMTP id d9443c01a7336-2902741e41emr283145525ad.55.1760405881703; Mon, 13 Oct 2025 18:38:01 -0700 (PDT) Received: from smtpclient.apple ([170.178.170.211]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29034f5840csm146802365ad.107.2025.10.13.18.37.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Oct 2025 18:38:01 -0700 (PDT) From: Chao Li Message-Id: <2E6A307F-BDB9-498F-AC93-B31E0023AD20@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_1112C3D0-4CDF-4509-B067-1FA8E74BA452" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: [PING] [PATCH v2] parallel pg_restore: avoid disk seeks when jumping short distance forward Date: Tue, 14 Oct 2025 09:37:45 +0800 In-Reply-To: <845486.1760402167@sss.pgh.pa.us> Cc: Dimitrios Apostolou , Nathan Bossart , Thomas Munro , pgsql-hackers@lists.postgresql.org To: Tom Lane References: <2edb7a57-b225-3b23-a680-62ba90658fec@gmx.net> <1282067.1744651649@sss.pgh.pa.us> <5ed51587-5a24-4d79-e36e-927620d0e3a2@gmx.net> <72d2c81b-a0fe-3d99-9dd4-0d771e6e673e@gmx.net> <1po8os49-r63o-2923-p37n-12698o1qn7p0@tzk.arg> <3515357.1760128017@sss.pgh.pa.us> <3698234.1760149336@sss.pgh.pa.us> <3686.1760232320@sss.pgh.pa.us> <717335.1760389672@sss.pgh.pa.us> <25A25667-AC82-46FD-A5FC-0B2AA0CC7DB9@gmail.com> <845486.1760402167@sss.pgh.pa.us> X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_1112C3D0-4CDF-4509-B067-1FA8E74BA452 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Oct 14, 2025, at 08:36, Tom Lane wrote: >=20 > Chao Li writes: >> I tested DEFAULT_IO_BUFFER_SIZE with 4K, 32K, 64K, 128K and 256K. = Looks like increasing the buffer size doesn=E2=80=99t improve the = performance significantly. Actually, with the buffer size 64K, 128K and = 256K, the test results are very close. I tested both with lz4 and none = compression. I am not suggesting tuning the buffer size. These data are = only for your reference. >=20 > Yeah, I would not expect straight pg_dump/pg_restore performance > to vary very much once the buffer size gets above not-too-many KB. > The thing we are really interested in here is how fast pg_restore > can skip over unwanted table data in a large archive file, and that > I believe should be pretty sensitive to block size. >=20 > You could measure that without getting into the complexities of > parallel restore if you make a custom-format dump of a few large > tables that does not have offset data in it, and then seeing how > fast is selective restore of just the last table. >=20 > =09 Not sure if I did something wrong, but I still don=E2=80=99t see much = difference between buffer size 4K and 128K with your suggested test. I created 3 tables, each with 10 millions of rows: ``` evantest=3D# CREATE TABLE tbl1 AS SELECT generate_series(1,10000000) AS = id; SELECT 10000000 evantest=3D# CREATE TABLE tbl2 AS SELECT generate_series(1,10000000) AS = id; SELECT 10000000 evantest=3D# CREATE TABLE tbl3 AS SELECT generate_series(1,10000000) AS = id; SELECT 10000000 ``` And did a custom-format dump: ``` % time pg_dump -Fc -f db.dump evantest pg_dump -Fc -f db.dump evantest 51.72s user 1.13s system 98% cpu 53.602 = total ``` Then pg_restore the last tabl, compiled with buffer size 4k and 128k: = (I dropped tbl3 before running pg_restore) ``` # 4K =3D=3D=3D % time pg_restore -d evantest -t tbl3 db.dump pg_restore -d evantest -t tbl3 db.dump 0.06s user 0.04s system 6% cpu = 1.528 total # 128K % time pg_restore -d evantest -t tbl3 db.dump pg_restore -d evantest -t tbl3 db.dump 0.05s user 0.04s system 3% cpu = 2.146 total ``` The other thing I noticed is that, when I do custom-format dump, if a = target file exists, pg_dump will just go ahead overwrite the existing = file; however, when I do directory dump, if a target dir exists, pg_dump = will fail with an error =E2=80=9Cdirectory xxx is not empty=E2=80=9D. = Why the behaviors are different? Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_1112C3D0-4CDF-4509-B067-1FA8E74BA452 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Oct 14, 2025, at 08:36, Tom Lane = <tgl@sss.pgh.pa.us> wrote:

Chao Li = <li.evan.chao@gmail.com> writes:
I = tested DEFAULT_IO_BUFFER_SIZE with 4K, 32K, 64K, 128K and 256K. Looks = like increasing the buffer size doesn=E2=80=99t improve the performance = significantly. Actually, with the buffer size 64K, 128K and 256K, the = test results are very close. I tested both with lz4 and none = compression. I am not suggesting tuning the buffer size. These data are = only for your reference.

Yeah, I would not expect = straight pg_dump/pg_restore performance
to vary very much once the = buffer size gets above not-too-many KB.
The thing we are really = interested in here is how fast pg_restore
can skip over unwanted = table data in a large archive file, and that
I believe should be = pretty sensitive to block size.

You could measure that without = getting into the complexities of
parallel restore if you make a = custom-format dump of a few large
tables that does not have offset = data in it, and then seeing how
fast is selective restore of just the = last table.

=

Not sure if I did = something wrong, but I still don=E2=80=99t see much difference between = buffer size 4K and 128K with your suggested = test.

I created 3 tables, each with 10 millions = of rows:

```
evantest=3D# CREATE = TABLE tbl1 AS SELECT generate_series(1,10000000) AS id;
SELECT = 10000000
evantest=3D# CREATE TABLE tbl2 AS SELECT = generate_series(1,10000000) AS id;
SELECT = 10000000
evantest=3D# CREATE TABLE tbl3 AS SELECT = generate_series(1,10000000) AS id;
SELECT = 10000000
```

And did a custom-format = dump:
```
% time pg_dump -Fc -f db.dump = evantest
pg_dump -Fc -f db.dump evantest  51.72s user = 1.13s system 98% cpu 53.602 = total
```

Then = pg_restore the last tabl,  compiled with buffer size 4k and 128k: = (I dropped tbl3 before running pg_restore)
```
# 4K = =3D=3D=3D
% time pg_restore -d evantest -t tbl3 = db.dump
pg_restore -d evantest -t tbl3 db.dump  0.06s = user 0.04s system 6% cpu 1.528 = total

# 128K
% = time pg_restore -d evantest -t tbl3 db.dump
pg_restore -d = evantest -t tbl3 db.dump  0.05s user 0.04s system 3% cpu 2.146 = total
```

The other thing = I noticed is that, when I do custom-format dump, if a target file = exists, pg_dump will just go ahead overwrite the existing file; however, = when I do directory dump, if a target dir exists, pg_dump will fail with = an error =E2=80=9Cdirectory xxx is not empty=E2=80=9D. Why the behaviors = are different?

Best regards,
--
Chao Li (Evan)
HighGo Software = Co., Ltd.
https://www.highgo.com/




= --Apple-Mail=_1112C3D0-4CDF-4509-B067-1FA8E74BA452--