Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jnj7y-0000HC-M5 for pgsql-general@arkaria.postgresql.org; Tue, 23 Jun 2020 13:38:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jnj7w-00032q-9m for pgsql-general@arkaria.postgresql.org; Tue, 23 Jun 2020 13:38:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jnj7w-00032j-1o for pgsql-general@lists.postgresql.org; Tue, 23 Jun 2020 13:38:16 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jnj7o-0001rH-Jh for pgsql-general@lists.postgresql.org; Tue, 23 Jun 2020 13:38:15 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 7BF945C036C; Tue, 23 Jun 2020 09:38:06 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 23 Jun 2020 09:38:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=x KUqLAgIDntxyWbpSeTZcnMhn4tBW2UO+aZbC34jegY=; b=HbrMejbkpiIhTTDXG D2ss+Jeckyq8PzgCnUxP6eSsbrW8ETiJZ0u0mnSIk7K1tAA6sTOTfArCS0sSu6GQ vNDkDkz3lu+gibsa8vorE5Wm9JJ6+TfJiyaR2lKS/twoQX57ZuTcUUM1PzuYmxuF r5DxTa/HSn6KXc9ni4wpcWKdaLtA5nmnf/0eo1IhVUgZYkg1VobaH1vrK4hV1ECT 0dFwnLT7HwBc3IpSOVwO73GEZvyro5uqGz2EXYBbKaBhseguOe3D7eGa0TpdEJFo KBXujK1T3ye2WeC24Wuo1/15P00/axz7VvN9ASOe+v96m2shq/mKWlYoUc2R+lVS ALwgg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=xKUqLAgIDntxyWbpSeTZcnMhn4tBW2UO+aZbC34je gY=; b=ezE6Ow7bB7tNalftoBuRU08wAB0FgZfdQeyVGEpF2Aymy0ofEucML/iqw OGKbLk+pk6pGp5mbZLTsMjbs6BDUz3lhhNb8IzJ2VwmaXBLbodgxoRsbP5O5Rn/k sREdv3vZ7iCXDuenoLBhog6hUnS1CoRMvaToYC//QR28M75dxEv7xXlD9gVsK3uD +grtUd4y0tnLu1E3VdSHJkfV9nQ2Eg2p0+enS2s7vKDPrJYXK8dHp0V/3JT0Fu5l lPoPL2pspAqDuBEdM7ForRfM/66/zgHWoqDMPbUYuQX+ZQvTgl3THqgdy0TqPcAK VBBt/uJJ7Cni5Ev/BVKwrM/cNNdpg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrudekhedggedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefheenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpedvkefhhefhleekjeeuueelhedvgeejfeehlefftefh tdefffefgeetfffgheefffenucfkphepjeehrddujedvrdehrddvfedunecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgr vhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: from [192.168.1.3] (75-172-5-231.tukw.qwest.net [75.172.5.231]) by mail.messagingengine.com (Postfix) with ESMTPA id D67C630674FC; Tue, 23 Jun 2020 09:38:05 -0400 (EDT) Subject: Re: UPDATE on 20 Million Records Transaction or not? To: Jason Ralph , "pgsql-general@lists.postgresql.org" References: From: Adrian Klaver Message-ID: <9c21c0a0-0897-125d-b27e-960bc357b0ef@aklaver.com> Date: Tue, 23 Jun 2020 06:38:05 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 6/23/20 6:32 AM, Jason Ralph wrote: > Hello List, > > PostgreSQL 11.8 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 > 20120313 (R > > ed Hat 4.4.7-23), 64-bit > > I am planning an update on a table with 20Million records, I have been > researching the best practices.  I will remove all indexes and foreign > keys prior to the update, however I am not sure if I should use a > transaction or not. > > My thought process is that a transaction would be easier to recover if > something fails, however it would take more time to write to the WAL log > in a transaction. Unless this is an UNLOGGED table WALs will be written. > > Would it make sense to make a back up of the table then execute update > without a transaction? How would you guys do it? You could break it down into multiple transactions if there is way to specify ranges of records. > > Thanks, > > *Jason Ralph* > > This message contains confidential information and is intended only for > the individual named. If you are not the named addressee you should not > disseminate, distribute or copy this e-mail. Please notify the sender > immediately by e-mail if you have received this e-mail by mistake and > delete this e-mail from your system. E-mail transmission cannot be > guaranteed to be secure or error-free as information could be > intercepted, corrupted, lost, destroyed, arrive late or incomplete, or > contain viruses. The sender therefore does not accept liability for any > errors or omissions in the contents of this message, which arise as a > result of e-mail transmission. If verification is required please > request a hard-copy version. -- Adrian Klaver adrian.klaver@aklaver.com