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 1txwvK-0009GK-2a for pgsql-performance@arkaria.postgresql.org; Thu, 27 Mar 2025 23:46:10 +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 1txwvH-00G073-Vj for pgsql-performance@arkaria.postgresql.org; Thu, 27 Mar 2025 23:46:07 +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.94.2) (envelope-from ) id 1txwvH-00G06A-Hi for pgsql-performance@lists.postgresql.org; Thu, 27 Mar 2025 23:46:07 +0000 Received: from mout.gmx.net ([212.227.15.19]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1txwvC-001bKx-1b for pgsql-performance@lists.postgresql.org; Thu, 27 Mar 2025 23:46:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1743119161; x=1743723961; i=jimis@gmx.net; bh=VaM2NuW6Mlur3JDc3xiRduaChsfbtj+4MtQQ+it4pLc=; h=X-UI-Sender-Class:Date:From:To:cc:Subject:In-Reply-To:Message-ID: References:MIME-Version:Content-Type:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=Eu3+BpecYCmvxv0DmQgasymEkBVrr3/S9gOnfJ3qVteppgYXo+6LM1Mtw6nmpJ/g 9IQWfZHOSyLm753c+d1wWD7n66Q0yoARM9RdiyrM3/pXIX44JZ4BEgnHO8QeKLcIN KP4/Co9LbROyOasi/+U4yw3gwfINfxDzVZ4Ut+m6kVwMTb+Ko5/JZBwbCJlzRm0oJ GfK9tDLnYewLesneJ0PsxkTusQL0Peo7egpSVezqYYNS32re2QpArEWotbBm3xWa5 /MJbFlcPh0rb32qqOfbd3KVhlmHs3XpYKk0d2fFterRN4TL3ZUyFvLQMI+9LdJD44 c4MEPHNzHyB2qlHsYA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [10.9.70.81] ([185.55.106.54]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MORAa-1tmMLe3vR8-00Qf7s; Fri, 28 Mar 2025 00:46:01 +0100 Date: Fri, 28 Mar 2025 00:45:58 +0100 (CET) From: Dimitrios Apostolou To: Tom Lane cc: pgsql-performance@lists.postgresql.org Subject: Re: parallel pg_restore blocks on heavy random read I/O on all children processes In-Reply-To: <3764bde7-ca09-a8a3-489c-0166f772245d@gmx.net> Message-ID: <1cbb9bd6-60cd-92cb-c3c2-4cf4fd8a7b64@gmx.net> References: <6bd16bdb-aa5e-0512-739d-b84100596035@gmx.net> <1095774.1742498237@sss.pgh.pa.us> <556498.1742744802@sss.pgh.pa.us> <3764bde7-ca09-a8a3-489c-0166f772245d@gmx.net> MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Provags-ID: V03:K1:ZSz9G3eNhXYuJhCiBHT58vNlKmylRSwNVTCUPhPYYLuBMgHXGoV +oGRdyOuIHwFKur0exFUgxv2vxIQkWIG7fr9jlJ0qdpzhExaerenrQr17b8HZlPWgv7gjlW pLS/gTqDPWvSmcqDQpFJEIbhytXWKAOdfIjg0ZpBI2uMI9ZD+BeDcjYCs0yt3tupLSlWX6Z f5rKsI/XJ6cU0KGd+P9kA== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:MbCB05mtw7I=;+0qIAdgvETEIZWnTqt6Lq9citDh 3leScbgDP0VMd53/H+EOUd0ON3AGHMeXLyMIuV9DfIXqX74a3Qi4h+HHIOV82a1jiiyu2JZnc keOWkijTUEJw4ak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mzF8sMOFHckFrKc r8197WxaZXO4kmmXA/7Rv2UCGPGn1xVXbg6bykoL0a0AuGYVNi8EQhhsvLSIN90O51z8O9bPN 9rWpxUCEs1F8ctP1dB3FNrOFDHVFKALc6ATMK3N86F7bSYI5lGsY17snXwtgyCvfSNrT+ai/f 9mkPTX2gj7d/KhnrSEK5W413Xf5cvfDLepEFFNC1tEF0GYAQDKmspCx9aB1GGqk07nrxwC0kJ VTMHneb8a2/PtF4/09Sexge1Hb65PwsltjbNgYnUHcy/snyhrdeTvVP6QtgaDX4NY3fsTNzlu bkxyFQwb2JTLrm6N5XZhHcfHb5i0= Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello again, I traced the seeking-reading behaviour of parallel pg_restore inside _skipData() when called from _PrintTocData(). Since most of today's I/O devices (both rotating and solid state) can read 1MB faster sequentially than it takes to seek and read 4KB, I tried the following change: diff --git a/src/bin/pg_dump/pg_backup_custom.c b/src/bin/pg_dump/pg_backup_custom.c index 55107b20058..262ba509829 100644 =2D-- a/src/bin/pg_dump/pg_backup_custom.c +++ b/src/bin/pg_dump/pg_backup_custom.c @@ -618,31 +618,31 @@ _skipLOs(ArchiveHandle *AH) * Skip data from current file position. * Data blocks are formatted as an integer length, followed by data. * A zero length indicates the end of the block. */ static void _skipData(ArchiveHandle *AH) { lclContext *ctx =3D (lclContext *) AH->formatData; size_t blkLen; char *buf =3D NULL; int buflen =3D 0; blkLen =3D ReadInt(AH); while (blkLen !=3D 0) { - if (ctx->hasSeek) + if (ctx->hasSeek && blkLen > 1024 * 1024) { if (fseeko(AH->FH, blkLen, SEEK_CUR) !=3D 0) pg_fatal("error during file seek: %m"); } else { if (blkLen > buflen) { free(buf); buf =3D (char *) pg_malloc(blkLen); buflen =3D blkLen; } if (fread(buf, 1, blkLen, AH->FH) !=3D blkLen) { if (feof(AH->FH)) This simple change improves immensely (10x maybe, depends on the number of workers) the offset-table building phase of the parallel backup. A problem still remaining is that this offset-table building phase is done on every worker process, which means that all workers scan almost in parallel the whole archive. A more intrusive improvement would be to move this phase to the parent process, before spawning the children. What do you think? Regards, Dimitris P.S. I also have a simple change that changes -j1 switch to mean "parallel but with one worker process", that I did for debugging purposes. Not sure if it is of interest here.