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 1tu87O-003ul0-7c for pgsql-performance@arkaria.postgresql.org; Mon, 17 Mar 2025 10:54:50 +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 1tu86M-00AgR6-N3 for pgsql-performance@arkaria.postgresql.org; Mon, 17 Mar 2025 10:53:46 +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 1tu86M-00AgQt-Ad for pgsql-performance@lists.postgresql.org; Mon, 17 Mar 2025 10:53:46 +0000 Received: from fhigh-b1-smtp.messagingengine.com ([202.12.124.152]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tu86I-003Lpi-0f for pgsql-performance@postgresql.org; Mon, 17 Mar 2025 10:53:45 +0000 Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.stl.internal (Postfix) with ESMTP id 6A1632540182; Mon, 17 Mar 2025 06:53:41 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Mon, 17 Mar 2025 06:53:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1742208821; x=1742295221; bh=L na3adiFpy36gfPnWZcZKzrU5FL2AuuEkchm14e2RIQ=; b=RUDKNR8mmH+ICFFri TCr6Z0IKh9ml71rKjdNpoYZlqO4ofUlUTRwNoCf2/uqF5AHL4q8lvLAqN1WfKnj9 JMguM7QEkA6H694eZ3A/vYRaK7Ifl6Hvu856idxkUyZ0qoMQCJTTgeluktB49RbB Rgbqny83g0g2avfUh+ywvB18Q9b85IYRiADQVvwXn3gtC1aAdBVdFM3ub/BlWmyu KLCteLdSja8+gT8U/1FPV0Wv5bqFh/lpXfEhIDN3oNglI12umNpTABNQB5Cf2CAN ykELlvnEyFwcqvXcbscnpYZttphCGCQ+/ekFMZCgrbOOZgzxPGQAojL5YkoDbnW3 Ju1kg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddufeelfedvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepfffhvfevuffkgggtugfgjgesthekredttddt jeenucfhrhhomheplmhlvhgrrhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlh hvhhdrnhhoqdhiphdrohhrgheqnecuggftrfgrthhtvghrnhepvdehueffhefgueekueef heehgffhuefgfedukeejveduffegffekgeffffevgeehnecuffhomhgrihhnpegvnhhtvg hrphhrihhsvggusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgpdhnsg gprhgtphhtthhopeefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehlrghurhgv nhiirdgrlhgsvgestgihsggvrhhtvggtrdgrthdprhgtphhtthhopehpghhsqhhlqdhpvg hrfhhorhhmrghntggvsehpohhsthhgrhgvshhqlhdrohhrghdprhgtphhtthhopegsihhl lhdrphhoohhlvgeshihmrghilhdrtghomh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 17 Mar 2025 06:53:40 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1742208817; bh=uU109rSDNpYujw/fdy7BPi22TGZUir3uZhFfE8VUFUc=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=PFlqzE7VA5IN8EvEAxsIJR07JpIg9StKvjrFmXXAuy3kAVaZOb8P5g+rDT0dFYvhr RWCA+zqmogCg6j4T0sD/6sSWBOv8sWFUgSOOcmRcJWp4+xx8Oh/tmlpESlHI+FalAW mmujH6M63KM83mZW0Y0Z29TO5Kn/0Oi1kAgBEfEkkIJ0D+YrN/PNe6xzaEWJDiSlAB XElNbFCi0ZLLaWasDo5aZENsnBaueKhEwR3t1zJ+At6QYKqLlMxzW+Dk37SaXL5Ls0 aF+lZwJ1RJl5Pu38WMrSEgH0os5jCW+hqtL5ftGIUUfGbN6yJ5wW/R8F9+SIe5KMe9 RTDlrvFG0rJ1g== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 7C9C587; Mon, 17 Mar 2025 11:53:37 +0100 (CET) Date: Mon, 17 Mar 2025 11:53:37 +0100 From: =?utf-8?Q?=C3=81lvaro?= Herrera To: bill.poole@ymail.com Cc: 'Laurenz Albe' , pgsql-performance@postgresql.org Subject: Re: Bulk DML performance Message-ID: <202503171053.nlf3ey2vm2vu@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <00b001db9418$85c7c770$91575650$@ymail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2025-Mar-13, bill.poole@ymail.com wrote: > I need to perform a merge (INSERT ... ON CONFLICT ... DO UPDATE) on > the data, so sadly I cannot use COPY. > > I have discovered that for some reason, performing the original insert > without the ON CONFLICT statement is twice as fast as performing the > original insert with an ON CONFLICT ... DO UPDATE clause, completing > in 4 seconds instead of 8. That seems strange to me because I wouldn't > have thought it would be doing any additional work since a unique > constraint is on the primary key, so each inserted value would need to > be checked in either case, and there is no extra work to be done in > either case. As I recall, INSERT .. ON CONFLICT UPDATE requires to _insert_ a value in the index prior to inserting the heap tuple, to guarantee uniqueness in face of potentially concurrent inserters of the same value. Maybe have a look at the WAL produced by the operation with "pg_waldump -z" to get some idea of the volume of each type of record. Maybe you could try to use MERGE rather than INSERT .. ON CONFLICT UPDATE. The concurrency modelling there is different, and it will probably have lower overhead. But you may need to lock the table explicitly to prevent concurrency problems. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "Doing what he did amounts to sticking his fingers under the hood of the implementation; if he gets his fingers burnt, it's his problem." (Tom Lane)