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 1spNNM-0010nB-5H for pgsql-general@arkaria.postgresql.org; Sat, 14 Sep 2024 07:39:25 +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 1spNNJ-006fKs-UL for pgsql-general@arkaria.postgresql.org; Sat, 14 Sep 2024 07:39:21 +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.94.2) (envelope-from ) id 1spNNJ-006fKj-FY for pgsql-general@lists.postgresql.org; Sat, 14 Sep 2024 07:39:21 +0000 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1spNNG-0015bZ-Bl for pgsql-general@lists.postgresql.org; Sat, 14 Sep 2024 07:39:19 +0000 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a8a706236bfso97973566b.0 for ; Sat, 14 Sep 2024 00:39:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20230601.gappssmtp.com; s=20230601; t=1726299556; x=1726904356; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=pTG5qZWb82SVix1V5c+gHBFVJPCJizDPfRFejj+89MA=; b=KxwsUrhdCV4fiUQlJQ2c5AQdMFzOVNFZKcl4oaW26jWH66ssNb5Bmsyun+Xpsi/IKP cGAIquntQB3frXL0jp+H5rULomtmBvi63+QksNgPKmwgPJQZu/7xhJ1nMya9ggUU6FR5 FuS8ZDQbETUlvh+oN1gEICfQE/SmA1sPVfMGOrS+MZZIidAY06g9LAf9IfGtXuFwOxjM dJBjl3d+4KIox231UvXBRmt4LQKGWrvEIA1MC2sJHI0W0W1AgEI1XEZSzcf180MrnARp HBVdRoafyMy130mY676hYtm/QRTnhPoDliHeD734FzoheRIMXTtd2Y+0JEDFPUGQHFKT qv8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726299556; x=1726904356; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=pTG5qZWb82SVix1V5c+gHBFVJPCJizDPfRFejj+89MA=; b=Q58cBnxfUSLhkIVuktHeGXxCbDh3qsu4lKYKhU5pIJf4g3ZoOdOvsgvxGCUX1J2ORY DdjuCmDc8vOIZ/t9CYoWH/L/czMbAF/s/Ohj2wthGddO09nse1jVjvtmpjDn0ayioiUG QWDtFLyuFaHiGTBeGoOVIUxgqGUII2hbxE6yXtiVFHpUlxQMZuPic1ZTgW79ND3CV7WA N3+Ls8m5qz743Lm4HGK7xa+glGdTNTVbaZzHPFbMXa1+YzwI69iwmwG+6caU+CBa6ZvS F9BUX9otxyjHxEdqmKq7CdEegHBN6NQCKxhAzte7LidzJGP8r0gA3ZcD+Pr63f/pG1XD Rkmg== X-Forwarded-Encrypted: i=1; AJvYcCXzrel+LfPlcjXqkTQBcQ4UkS+Exw/GVyk8ezCV5jeS7u/geNgI4SASpBoaq5YkTH3QHcXK8fh8yTKsfpW2@lists.postgresql.org X-Gm-Message-State: AOJu0Ywily8CnEZkSe3RpR4aCZEGUVxaTWQRE3mdukaQCkuIjbHivb/L EAowAvM0uolzvKJmFczvbNIMla171XWzVS+TiWJ6WUHoMoxuJ299nj3eR4frlrg= X-Google-Smtp-Source: AGHT+IEWtNf8laFh8gtzGMi1nyJeEzT06Z66TsggEwdW0/BnPPsDAYlG5BbLXEttawpIZ7Stcr0AZg== X-Received: by 2002:a05:6402:5108:b0:5c2:6311:c9d1 with SMTP id 4fb4d7f45d1cf-5c41e1b5325mr5912821a12.22.1726299555293; Sat, 14 Sep 2024 00:39:15 -0700 (PDT) Received: from dynamic-pd01.res.v6.highway.a1.net ([2001:871:260:35ac:ea40:e2b4:803a:2aad]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9061328e61sm44403066b.196.2024.09.14.00.39.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Sep 2024 00:39:14 -0700 (PDT) Message-ID: <1955d0e6cafd643520d282a74d9956340983074e.camel@cybertec.at> Subject: Re: update faster way From: Laurenz Albe To: yudhi s , pgsql-general Date: Sat, 14 Sep 2024 09:39:14 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.4 (3.52.4-1.fc40) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, 2024-09-14 at 08:43 +0530, yudhi s wrote: > We have to update a column value(from numbers like '123' to codes like 'a= bc' > by looking into a reference table data) in a partitioned table with billi= ons > of rows in it, with each partition having 100's millions rows. As we test= ed > for ~30million rows it's taking ~20minutes to update. So if we go by this > calculation, it's going to take days for updating all the values. So my > question is >=20 > 1) If there is any inbuilt way of running the update query in parallel > (e.g. using parallel hints etc) to make it run faster? > 2) should we run each individual partition in a separate session (e.g. fi= ve > partitions will have the updates done at same time from 5 different > sessions)? And will it have any locking effect or we can just=C2=A0sta= rt the > sessions and let them run without impacting our live transactions? Option 1 doesn't exist. Option 2 is possible, and you can even have more than one session workingr on a single partition. However, the strain on your system's resources and particularly the row locks will impair normal database work. Essentially, you can either take an extended down time or perform the updat= es in very small chunks with a very low "lock_timeout" over a very long period of time. If any of the batches fails because of locking conflicts, it has to be retried. Investigate with EXPLAIN (ANALYZE) why the updates take that long. It coul= d be a lame disk, tons of (unnecessary?) indexes or triggers, but it might as well be the join with the lookup table, so perhaps there is room for improvement (more "work_mem" for a hash join?). Yours, Laurenz Albe