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.96) (envelope-from ) id 1vJe1i-00EQjz-2c for pgsql-hackers@arkaria.postgresql.org; Thu, 13 Nov 2025 20:34:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vJe1g-003KHU-1x for pgsql-hackers@arkaria.postgresql.org; Thu, 13 Nov 2025 20:34:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vJe1g-003KHM-0s for pgsql-hackers@lists.postgresql.org; Thu, 13 Nov 2025 20:34:40 +0000 Received: from mail-qt1-x836.google.com ([2607:f8b0:4864:20::836]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vJe1d-007bNs-2U for pgsql-hackers@lists.postgresql.org; Thu, 13 Nov 2025 20:34:40 +0000 Received: by mail-qt1-x836.google.com with SMTP id d75a77b69052e-4edb8d6e98aso91791cf.0 for ; Thu, 13 Nov 2025 12:34:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763066076; x=1763670876; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=1JWSKXZF85ARyZ+UrzpWkmYyaNE2bsOKcIirUK3jvhQ=; b=3Euz2yB3BY9OxYdTdwj4JnTVxmZ1ssM4Tg56voa0v15oVUnAKSgYlDx4eJ5VnepLNw d/9LK4pCeHJcZAaoIxi7wJUb+jnDxOlrvcj4lGCZyuKGvmem3chJ+BqsOFNo8f12RMMa yAP5L1pjXXlxAqAyn/P7rex3pb0JMcioOnCgtOaTR+CtI/pEoX49bFcixjnXm2XrMNdY olFmhb9avImAKzOFai5u5Hk17CBq3mFAciDrEf/KuG8d4JzvGdBJIMqg7laG4zGZfWag u1mDdiBdYEljlTHBEKXWqsGax0njMLjbfXW7HeCP5dfwirW7/GfSwQAN86D3W36x9HvK 0QCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763066076; x=1763670876; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=1JWSKXZF85ARyZ+UrzpWkmYyaNE2bsOKcIirUK3jvhQ=; b=dq4NzMb0f/VGEgdTKt9GgTv8Q4wxbtAuDpVVJ68Whivdtx3mfFOYTV4qZEcv8hlc82 OdyZqmaMljp/dTLFUER57VAid8txFLhD45H7Yd541o0ksK5XLBdrutKHOid6SUxy7GfF BeBUnn8oAUTGzO0TNEsHsAgspliPR7OfMYx0EjvkTi3gOR/Q33Bj9MUIx71m6dR9Hm1R coGQY4H99QDxlydR076eagTqOSd5Pn3KY9SCJ/QymwlPRrPO+Ekm3/gzewZEj7LTkplF O4IgeT4hHzkWh3YS8rABsMpL8kcHl5sGLhtzTigjh2xiIFISzr4x0HfZhpUwypknBk3h P0FQ== X-Gm-Message-State: AOJu0YyT3n4DhQn/54g7uBZEmK+x4TZv1ZhGPtVfA3O7mznRfyNeExVI PGayd7OxLXKCXm5/6UnKopmAraLmyPCqwSG28+V3i/hIkhtBS3VX+IsHu1cj00wsC/3orfnUQr2 vpGo5FGHJigO5mI3ZXkwC761VAWGEUKD0J0DDOOeq X-Gm-Gg: ASbGnctW2oNu1PotBNc1SknG0cLi0gEj8/VJqwI112rOExa2Nd9xLsX3uEJvsHYEwzL a5r9q6bYKoep1nvGBmsZ+oTDPcvde2J+il1FRjPZj3TlPM76HPqZXTI0kyB3U4y+g6tFvhC0paA hr7aRadyquyJC8d+5YbU7bBpTFwfupoBKuD0XZoc/DOsIALHP3x6DaT9RXAdLzqL03FnPK3FOx0 3pUfu+aC0ahf7bdkFd3qt6N4Zdl+WA9m0pKMeGgeg3hASrjtJ9s48hJoPpjzBmsIbc/2qbEyyhG crOr X-Google-Smtp-Source: AGHT+IHM3TH01tvjebvDIXuUBTsJZRB5FAqzQaAEBIN7D83wE0Z85NpYnHx30VqLj3n/ppBurmMgFlRYzcAVPI6+vyo= X-Received: by 2002:ac8:5949:0:b0:4b7:9b06:ca9f with SMTP id d75a77b69052e-4edf3135e8emr1184801cf.2.1763066075432; Thu, 13 Nov 2025 12:34:35 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Hannu Krosing Date: Thu, 13 Nov 2025 21:34:23 +0100 X-Gm-Features: AWmQ_bm5_uLer6NA5avEXXUWYuUZdlj1ZD_c52ahf8r8xbfQ5QI8iYxRRdTYaEE Message-ID: Subject: Re: Patch: dumping tables data in multiple chunks in pg_dump To: Ashutosh Bapat Cc: PostgreSQL Hackers , Nathan Bossart Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Added to https://commitfest.postgresql.org/patch/6219/ On Thu, Nov 13, 2025 at 9:26=E2=80=AFPM Hannu Krosing w= rote: > > The reason for small chunk sizes is that they are determined by main > heap table, and that was just over 1GB > > largetoastdb=3D> SELECT format('%I.%I', t.schemaname, t.relname) as table= _name, > pg_table_size(t.relid) AS table_size, > sum(pg_relation_size(i.indexrelid)) AS total_index_size, > pg_relation_size(t.relid) AS main_table_size, > pg_relation_size(c.reltoastrelid) AS toast_table_size, > pg_relation_size(oi.indexrelid) AS toast_index_size, > t.n_live_tup AS row_count, > count(*) AS index_count, > array_to_json(array_agg(json_build_object(i.indexrelid::regclass, > pg_relation_size(i.indexrelid))), true) AS index_info > FROM pg_stat_user_tables t > JOIN pg_stat_user_indexes i ON i.relid =3D t.relid > JOIN pg_class c ON c.oid =3D t.relid > LEFT JOIN pg_stat_sys_indexes AS oi ON oi.relid =3D c.reltoastrelid > GROUP BY 1, 2, 4, 5, 6, 7 > ORDER BY 2 DESC, 7 DESC > LIMIT 25; > =E2=94=8C=E2=94=80[ RECORD 1 ]=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=AC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 > =E2=94=82 table_name =E2=94=82 public.just_toasted = =E2=94=82 > =E2=94=82 table_size =E2=94=82 56718835712 = =E2=94=82 > =E2=94=82 total_index_size =E2=94=82 230064128 = =E2=94=82 > =E2=94=82 main_table_size =E2=94=82 1191559168 = =E2=94=82 > =E2=94=82 toast_table_size =E2=94=82 54613336064 = =E2=94=82 > =E2=94=82 toast_index_size =E2=94=82 898465792 = =E2=94=82 > =E2=94=82 row_count =E2=94=82 5625234 = =E2=94=82 > =E2=94=82 index_count =E2=94=82 1 = =E2=94=82 > =E2=94=82 index_info =E2=94=82 [{"just_toasted_pkey" : 230064128}] = =E2=94=82 > =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=B4=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=98 > > On Thu, Nov 13, 2025 at 9:24=E2=80=AFPM Hannu Krosing = wrote: > > > > Ran another test with a 53GB database where most of the data is in TOAS= T > > > > CREATE TABLE just_toasted( > > id serial primary key, > > toasted1 char(2200) STORAGE EXTERNAL, > > toasted2 char(2200) STORAGE EXTERNAL, > > toasted3 char(2200) STORAGE EXTERNAL, > > toasted4 char(2200) STORAGE EXTERNAL > > ); > > > > and the toast fields were added in somewhat randomised order. > > > > Here the results are as follows > > > > Parallelism | chunk size (pages) | time (sec) > > 1 | - | 240 > > 2 | 1000 | 129 > > 4 | 1000 | 64 > > 8 | 1000 | 36 > > 16 | 1000 | 30 > > > > 4 | 9095 | 78 > > 8 | 9095 | 42 > > 16 | 9095 | 42 > > > > The reason larger chunk sizes performed worse was that they often had > > one or two stragglers left behind which > > > > Detailed run results below: > > > > hannuk@pgn2:~/work/postgres/src/bin/pg_dump$ time ./pg_dump > > --format=3Ddirectory -h 10.58.80.2 -U postgres -f > > /tmp/ltoastdb-1-plain.dump largetoastdb > > real 3m59.465s > > user 3m43.304s > > sys 0m15.844s > > > > hannuk@pgn2:~/work/postgres/src/bin/pg_dump$ time ./pg_dump > > --format=3Ddirectory -h 10.58.80.2 -U postgres > > --huge-table-chunk-pages=3D9095 -j 4 -f /tmp/ltoastdb-4.dump > > largetoastdb > > real 1m18.320s > > user 3m49.236s > > sys 0m19.422s > > > > hannuk@pgn2:~/work/postgres/src/bin/pg_dump$ time ./pg_dump > > --format=3Ddirectory -h 10.58.80.2 -U postgres > > --huge-table-chunk-pages=3D9095 -j 8 -f /tmp/ltoastdb-8.dump > > largetoastdb > > real 0m42.028s > > user 3m55.299s > > sys 0m24.657s > > > > hannuk@pgn2:~/work/postgres/src/bin/pg_dump$ time ./pg_dump > > --format=3Ddirectory -h 10.58.80.2 -U postgres > > --huge-table-chunk-pages=3D9095 -j 16 -f /tmp/ltoastdb-16.dump > > largetoastdb > > real 0m42.575s > > user 4m11.011s > > sys 0m26.110s > > > > hannuk@pgn2:~/work/postgres/src/bin/pg_dump$ time ./pg_dump > > --format=3Ddirectory -h 10.58.80.2 -U postgres > > --huge-table-chunk-pages=3D1000 -j 16 -f /tmp/ltoastdb-16-1kpages.dump > > largetoastdb > > real 0m29.641s > > user 6m16.321s > > sys 0m49.345s > > > > hannuk@pgn2:~/work/postgres/src/bin/pg_dump$ time ./pg_dump > > --format=3Ddirectory -h 10.58.80.2 -U postgres > > --huge-table-chunk-pages=3D1000 -j 8 -f /tmp/ltoastdb-8-1kpages.dump > > largetoastdb > > real 0m35.685s > > user 3m58.528s > > sys 0m26.729s > > > > hannuk@pgn2:~/work/postgres/src/bin/pg_dump$ time ./pg_dump > > --format=3Ddirectory -h 10.58.80.2 -U postgres > > --huge-table-chunk-pages=3D1000 -j 4 -f /tmp/ltoastdb-4-1kpages.dump > > largetoastdb > > real 1m3.737s > > user 3m50.251s > > sys 0m18.507s > > > > hannuk@pgn2:~/work/postgres/src/bin/pg_dump$ time ./pg_dump > > --format=3Ddirectory -h 10.58.80.2 -U postgres > > --huge-table-chunk-pages=3D1000 -j 2 -f /tmp/ltoastdb-2-1kpages.dump > > largetoastdb > > real 2m8.708s > > user 3m57.018s > > sys 0m18.499s > > > > On Thu, Nov 13, 2025 at 7:39=E2=80=AFPM Hannu Krosing wrote: > > > > > > Going up to 16 workers did not improve performance , but this is > > > expected, as the disk behind the database can only do 4TB/hour of > > > reads, which is now the bottleneck. (408/352/*3600 =3D 4172 GB/h) > > > > > > $ time ./pg_dump --format=3Ddirectory -h 10.58.80.2 -U postgres > > > --huge-table-chunk-pages=3D131072 -j 16 -f /tmp/parallel16.dump large= db > > > real 5m44.900s > > > user 53m50.491s > > > sys 5m47.602s > > > > > > And 4 workers showed near-linear speedup from single worker > > > > > > hannuk@pgn2:~/work/postgres/src/bin/pg_dump$ time ./pg_dump > > > --format=3Ddirectory -h 10.58.80.2 -U postgres > > > --huge-table-chunk-pages=3D131072 -j 4 -f /tmp/parallel4.dump largedb > > > real 10m32.074s > > > user 38m54.436s > > > sys 2m58.216s > > > > > > The database runs on a 64vCPU VM with 128GB RAM, so most of the table > > > will be read in from the disk > > > > > > > > > > > > > > > > > > > > > On Thu, Nov 13, 2025 at 7:02=E2=80=AFPM Hannu Krosing wrote: > > > > > > > > I just ran a test by generating a 408GB table and then dumping it b= oth ways > > > > > > > > $ time pg_dump --format=3Ddirectory -h 10.58.80.2 -U postgres -f > > > > /tmp/plain.dump largedb > > > > > > > > real 39m54.968s > > > > user 37m21.557s > > > > sys 2m32.422s > > > > > > > > $ time ./pg_dump --format=3Ddirectory -h 10.58.80.2 -U postgres > > > > --huge-table-chunk-pages=3D131072 -j 8 -f /tmp/parallel8.dump large= db > > > > > > > > real 5m52.965s > > > > user 40m27.284s > > > > sys 3m53.339s > > > > > > > > So parallel dump with 8 workers using 1GB (128k pages) chunks runs > > > > almost 7 times faster than the sequential dump. > > > > > > > > this was a table that had no TOAST part. I will run some more tests > > > > with TOASTed tables next and expect similar or better improvements. > > > > > > > > > > > > > > > > On Wed, Nov 12, 2025 at 1:59=E2=80=AFPM Ashutosh Bapat > > > > wrote: > > > > > > > > > > Hi Hannu, > > > > > > > > > > On Tue, Nov 11, 2025 at 9:00=E2=80=AFPM Hannu Krosing wrote: > > > > > > > > > > > > Attached is a patch that adds the ability to dump table data in= multiple chunks. > > > > > > > > > > > > Looking for feedback at this point: > > > > > > 1) what have I missed > > > > > > 2) should I implement something to avoid single-page chunks > > > > > > > > > > > > The flag --huge-table-chunk-pages which tells the directory for= mat > > > > > > dump to dump tables where the main fork has more pages than thi= s in > > > > > > multiple chunks of given number of pages, > > > > > > > > > > > > The main use case is speeding up parallel dumps in case of one = or a > > > > > > small number of HUGE tables so parts of these can be dumped in > > > > > > parallel. > > > > > > > > > > Have you measured speed up? Can you please share the numbers? > > > > > > > > > > -- > > > > > Best Wishes, > > > > > Ashutosh Bapat