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 1wA2Ia-0020MK-16 for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Apr 2026 09:00:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wA2IY-00G2CT-2e for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Apr 2026 09:00:39 +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.96) (envelope-from ) id 1wA2IY-00G2CK-1j for pgsql-hackers@lists.postgresql.org; Tue, 07 Apr 2026 09:00:38 +0000 Received: from lahtoruutu.iki.fi ([185.185.170.37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wA2IW-000000010Gp-2uai for pgsql-hackers@lists.postgresql.org; Tue, 07 Apr 2026 09:00:38 +0000 Received: from [10.0.2.15] (unknown [130.41.208.1]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4fqgC11b7Hz49Q2v; Tue, 07 Apr 2026 12:00:29 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1775552429; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P1XwXaBtfmTuUUuFQtgEKZPCJ4yPxgzFpLRR8q/8lFg=; b=VsB9j/mqZ/AbNfAeoFlxzhclUJGCBnUQATu5DLJ/qKfJidFnf7D5B0C5rJupX4Blh3Qnx+ jzrl8OkkypIfh15wHrCX/cfnx3BCnKgYCAhCefGJ05gTtQQeelKEp6MIOQSg8pix4rJzxt KP29gepluTBx3kQXRvgrwjAAZa+Pf1GuL0x65qLZiu3wPUs6+CHV8Tz0jl9V5prP81zM0U 4GVLuRVTIuW/7OvfnjwXJhV3kf+B9bm1W3YwU/gcicFe2SCC2nueLprhL4HT8djKQ54DDM PMgUlbrXuphalxbrG82+d4h316TLfFpY1Cm2ChCAHGnvLyEWB/AFdreKgpYPzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1775552429; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P1XwXaBtfmTuUUuFQtgEKZPCJ4yPxgzFpLRR8q/8lFg=; b=hotz9MtqVzLUY78dKFqOG2Pm5BuLE0hu6+ja7p5P4g1XwEA+NRigyb7f+/ZtpamhYEF0R8 Xfg81JHewgZ0MHD6Ft8BfE+nRlLLAQVNWF+K/OGu2wG/LB0j74dq/XipOK3f9omVol3OIg g/YEQ+sjDrvLvmNYO7ZEb6EX8OBfZkh9Umrb/yGW3o6xEAda9Dh5TPhSiAuGTsKUFLFqDx gXW2cna+Iu1pf5qAUom63bWw+pA50YswqvC88u1Lsf2cjsmUFlgNN5gS4pLH07AvPm4keB S9/SDulzDQW7kyqg6TmYjG4+ncpu+drXpbCMSS0isSYDjenTvyOusQ2tyfFYIQ== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=lahtoruutu; cv=none; t=1775552429; b=jlsxsic/hKqEXz/zUsrsWSTIiGYcXRjxANWWFFfkbLFym3ZPYg4TFplLnFXCFgPE1zm/a1 wTfCO1f+FyDgoji8RKzdEaWLrDbiE3Hb+LPddipKKS+XVFUFPWaTlirGHn0lZCWn1DWQew MGf3oK5ZguYZHGieIQC9T9+I25+VT7TA0Z1aUs1cxALfTND7Z4YsiCVEz/qbtrKQW3sYx6 eDRWJmBooCDOKyMnWdoMT0TvL8M4QSZFKXumhFEQcskzxT/3lQeKaUhE364RFHi3txl7cb Vz+46/Binsq9N2/7gdeB4OicWJBCgfhOv4hzvR2fNN9ONAXU2ZAJ51YpHWyqBQ== Message-ID: Date: Tue, 7 Apr 2026 12:00:28 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: parallel data loading for pgbench -i To: lakshmi , Mircea Cadariu Cc: "Hayato Kuroda (Fujitsu)" , PostgreSQL Hackers , "tomas@vondra.me" References: <4c1d0b97-a5f8-472c-afdd-bdeb09b93f33@gmail.com> <10868918-cdf9-49dc-99af-8e8ccd6e368c@gmail.com> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 18/03/2026 12:37, lakshmi wrote: > So overall, the benefit of parallel loading is much clearer in the > partitioned case. > > I’ll try to look further into the VACUUM behavior. As discussed already, the slower VACUUM is surely because of the lack of COPY FREEZE option. That's unfortunate... The way this patch uses the connections and workers is a little bonkers. The main thread uses the first connection to execute: begin; TRUNCATE TABLE pgbench_accounts; That connection is handed over to the first worker thread, and new connections are opened for the other workers. But thanks to the TRUNCATE, the open transaction on the first connection holds an AccessExclusiveLock, preventing the other workers from starting the COPY until the first worker has finished! I added some debugging prints to show this: $ pgbench -s500 -i -j10 postgres dropping old tables... creating tables... generating data (client-side)... loading pgbench_accounts with 10 threads... 0.00: thread 0: sending COPY command, use_freeze: 1 0.00: thread 1: sending COPY command, use_freeze: 0 0.00: thread 2: sending COPY command, use_freeze: 0 0.00: thread 0: COPY started for rows between 0 and 5000000 0.00: thread 6: sending COPY command, use_freeze: 0 0.00: thread 3: sending COPY command, use_freeze: 0 0.00: thread 9: sending COPY command, use_freeze: 0 0.00: thread 4: sending COPY command, use_freeze: 0 0.00: thread 5: sending COPY command, use_freeze: 0 0.00: thread 7: sending COPY command, use_freeze: 0 0.00: thread 8: sending COPY command, use_freeze: 0 6.19: thread 0: COPY done! 6.27: thread 9: COPY started for rows between 45000000 and 50000000 6.27: thread 1: COPY started for rows between 5000000 and 10000000 6.27: thread 5: COPY started for rows between 25000000 and 30000000 6.27: thread 2: COPY started for rows between 10000000 and 15000000 6.27: thread 6: COPY started for rows between 30000000 and 35000000 6.27: thread 3: COPY started for rows between 15000000 and 20000000 6.27: thread 8: COPY started for rows between 40000000 and 45000000 6.27: thread 4: COPY started for rows between 20000000 and 25000000 6.27: thread 7: COPY started for rows between 35000000 and 40000000 19.19: thread 1: COPY done! 19.21: thread 9: COPY done! 19.26: thread 6: COPY done! 19.27: thread 7: COPY done! 19.28: thread 3: COPY done! 19.28: thread 5: COPY done! 19.28: thread 4: COPY done! 19.29: thread 8: COPY done! 19.36: thread 2: COPY done! vacuuming... creating primary keys... done in 71.58 s (drop tables 0.07 s, create tables 0.01 s, client-side generate 19.41 s, vacuum 26.50 s, primary keys 25.59 s). The straightforward fix is to commit the TRUNCATE transaction, and not use FREEZE on any of the COPY commands. This all makes more sense in the partitioned case. Perhaps we should parallelize only when partitioned are used, and use only one thread per partition. - Heikki