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 1rt9Kh-00CdG0-50 for pgsql-general@arkaria.postgresql.org; Sat, 06 Apr 2024 16:55:59 +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 1rt9Kg-00ECs2-9P for pgsql-general@arkaria.postgresql.org; Sat, 06 Apr 2024 16:55:58 +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 1rt9Kf-00ECru-C4 for pgsql-general@lists.postgresql.org; Sat, 06 Apr 2024 16:55:57 +0000 Received: from wfhigh8-smtp.messagingengine.com ([64.147.123.159]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rt9Kb-0014jG-IV for pgsql-general@lists.postgresql.org; Sat, 06 Apr 2024 16:55:56 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.west.internal (Postfix) with ESMTP id 342DA1800087; Sat, 6 Apr 2024 12:55:49 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sat, 06 Apr 2024 12:55:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1712422548; x=1712508948; bh=UKnQMfh34OaK/FwZN/ZSSle3mWMq1t3l+Swtoj64A9o=; b= JinBUVlZncGyc+SGSKjmF8KEFuQPmFcGVj4a/GBA5MwyWthkU4HHPfa2c0BdG8uD 2Fgn7dAtBy4DdJBPo76qP7NbtUYHKCF+YAHxJHrOhhPPYgeg3Fv/1+hLDJA8oJjr 63ROwFwldZhmjvNKLgI/miwibUeXN1X2IurPopS6Q6X2T1vt5ILeW7sbkTBCHxRa nyUf/KMYGnq+WtunhkrdQl8xwPaiM/1BHJ5/bRM+oTCKkRku71e8YpqYFvAw9CuK G4E3PjbQbZF4be1P/+gDQIi2AuSJrXK8ZDS3Z3tV3Z3kmq4cVOxsWdZwFHB1Xoz9 aHdFK1wx9LKaQ3Tg808zUw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1712422548; x= 1712508948; bh=UKnQMfh34OaK/FwZN/ZSSle3mWMq1t3l+Swtoj64A9o=; b=i fn7uF7BYa7jNdVHultuB4oku2zDRsYkKqfSNV9/MbkJzq7CCkI8ocA9YJAhd1rIH Hj8rpaW7P2IRa/lwoTe8UHS0D09wGJzLQ+rSAtGXrVZmJPMRcW3rc5P1dDhVcBdp tVGvfn0MOmSW2Ux2yLSbJgzYQ+Qns8jc/hEPKepgYN4xcM44YwIWth9sgRfrl6Wn LEmsxrTUHgyzrxTK5hheKNyaQ1WBmQ8w7PeU4UhIFlyG83v9ksIlE6ktJioOj2Cj 5K+zOmbWF9aUMVygY0W3H8fZHteNw/D30aI0Jwx33trF+QLRAjblTe9PaLZrIZpZ ZEcZMQpK349euPKl2DlIw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudegvddguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertddtvdejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecuggftrfgrthhtvghrnhepffelgeeifefgveduhedthfekuedtffejveegffeg jeevtdehgfduieetfeehjeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 6 Apr 2024 12:55:47 -0400 (EDT) Message-ID: Date: Sat, 6 Apr 2024 09:55:47 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Moving delta data faster To: yudhi s , veem v , Greg Sabino Mullane , pgsql-general References: Content-Language: en-US From: Adrian Klaver 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 4/6/24 08:47, yudhi s wrote: > Thank you Adrian, Greg and Veem. > > I tried writing a small routine to see how the performance differs in > these four approaches i.e. Upsert VS traditional update+insert VS Merge > vs Truncate+load. > > Initially I was thinking Upsert will perform the same as Merge as the > logic looks similar but it seems it's the worst performing among all, > not sure why , yet to know the reason though. Truncate+ load seems to be > the best performing among all. Hope i am doing it correctly. Please > correct me if I'm wrong. Your original problem description was: "Then subsequently these rows will be inserted/updated based on the delta number of rows that got inserted/updated in the source database. In some cases these changed data can flow multiple times per day to the downstream i.e. postgres database and in other cases once daily." If the above is not a hard rule, then yes up to some point just replacing the data in mass would be the simplest/fastest method. You could cut a step out by doing something like TRUNCATE target_tab and then COPY target_tab FROM 'source.csv' bypassing the INSERT INTO source_tab. -- Adrian Klaver adrian.klaver@aklaver.com