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 1tKKUM-0084zH-49 for pgsql-sql@arkaria.postgresql.org; Sun, 08 Dec 2024 16:50:34 +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 1tKKUJ-001sMF-9h for pgsql-sql@arkaria.postgresql.org; Sun, 08 Dec 2024 16:50:32 +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 1tKKUI-001sM7-UB for pgsql-sql@lists.postgresql.org; Sun, 08 Dec 2024 16:50:32 +0000 Received: from mout.perfora.net ([74.208.4.196]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tKKUD-001h7v-Ev for pgsql-sql@lists.postgresql.org; Sun, 08 Dec 2024 16:50:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sopchak.me; s=s1-ionos; t=1733676623; x=1734281423; i=carl@sopchak.me; bh=fxXbv9K4vsZyeoEMwSV3N/RfoFNtUdxYniLMpSGhitE=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:Subject:To: References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=nGTHJSmGqyOem242eEOAmKTC7iJU0j/85nmsnoh1EQveKKyoOld+sM4eEwFvI/Uy fTSgcyxjm7EuEVHxM68cy27oCEIL2qV09f2Tgn5XsGG0O77H8Smi/jN7q920s0UxK fXE52mn5IxptXOF3M3PW/fd6kMsGK1XbnWbt/tdYYhVnAikCIbv2j5oxiyd+cdoJA 134TrthS6m74Sy7ZopWY2VRP6p/PDXGrtAleN/+0whCT1NPXbjBS1gc+x2TKojV+7 AaYXgseWsLAU9OP4Wj/RJiyPVKuOidmhQlq9vD1S7CxwyNsujRcD/hak9AzUOWcT0 I5i/Q50dX+BdHLGcmQ== X-UI-Sender-Class: 55c96926-9e95-11ee-ae09-1f7a4046a0f6 Received: from [10.221.133.171] ([142.105.135.230]) by mrelay.perfora.net (mreueus002 [74.208.5.2]) with ESMTPSA (Nemesis) id 0M7qkg-1tXL8J0RtI-00qooZ for ; Sun, 08 Dec 2024 17:50:23 +0100 Message-ID: Date: Sun, 8 Dec 2024 11:50:21 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: What is the best way to do this in Postgres To: pgsql-sql@lists.postgresql.org References: Content-Language: en-US From: Carl Sopchak In-Reply-To: Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:fz5JjD64bOVD74J+he0FhJ9tCOYXbL3on+LgWdRY9fnS5wfx+Hh ICm10uDGMU4rIrPAI48eW15cp+wq87gjwCHYtJqM9eifYCZGAad5n32bSVLfxiEeTeyhoH6 Ggxy5Xj1rlYhS7FU2pIqLo1U4xQ+sZfD9M3nDdtYqhjbXDuqP3Sd8QDrn2v3YDtXpnuQ65F zsElRd5i8ZEb7veKSOFpQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:p0vs6BQF+Uc=;kgMbTIiRrUjcK7hXcW7Plx8+nGW KI7xDlsDejYnEZTOiMNYhNV98h7NMvHZN9cxSbEiJbJEhmU7N1Yh7IeJg9ztPmzfh2raCRhRF eETQhBlJuNF8buh8yDa8iz8Le2fdXvhA2PSkmCOmapvUPu44fAib6S9KmOLoO2jFb4e93yeI3 Fw9N7zc+c+HbZMcPvk0DqGEQrFrGTwnc4ZHUOF34CA+5J/Qhig02WW5W/FS9tGX6dQ2thxLaH ZY6Pb+yCHqw0+NGuGaaKcnJJh3wG0nNxLkrDqTrlrt1S50onELyjbWVnm6hkbpie+awzPsBmz Ff/vyr+MKdUcXDImNoKPtrNP+XIAcsT6vcAZGO44+ZM/7GaTFOaNsF3ZT8rUamGPtzY+XXEbx gu7L3lU1gb2ZS+g05hXYbGc6XMrpzbX88mf1oLLDjQs2JNSW8abAd1Hqcot8dbdRSSn81SU/X 1xPQOu/565p08s/FLvvgamJEfKZtezBDsk+/SJXqub0xMZ3xHb5W3zRLBO/BZPjtH8fHAmy6p wW0kCVI54WzeMl6DCOw2s/LT3uA8vHfTizh8ZZ+AZpCRUNcUqGe4LICgmEtgOyW1ly/oHToQe u1ppAA1u23pgaAAFMX7DGLQOZOLlH5I+2KbveFxU5tPO4cV1C0EnI8O7h323M7Ck7h0rd0LDs U0MNwLpayZR7WHBpBQEtQj3NQuWuJiyvSqGczOjq74+GLqKzRKU/5NX06nQwy7nfZ3YFMmtRp 7+dCfA2xMi6U0EnONFLd1mKwl4pXqm9L7hN1+KJNRYVwYgj9DHlAMrnBdR0yyQJl+nJAOl36d CA1hp0KnQVVgDkYvC0hR5PH6gf8q90ohCF1fGhtgFUOOSlrjjxriYFiCHBTgdTjC1sFfoio8g yeTRQFPZW2oM1U9pEAzQefYhAPaNfrDNllqkqEzG5Q4zqRlbntJN7MQNyrFIpPvuT9cuDnjjh PnZ37qnMnR+fp6Who9V0hExIOco6tDqvI4euFp+VbUZ3Bj7axhYkXbm0xY+cEjdMMLziiUZpk WOajspdgLxT77p74ICl7sKyKEpEp3tUZPKN1cec List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk You could set up a queuing table to hold the product id's that need processing, removing that parameter from the proc (or all of them if all columns vary and are in the queuing table).=C2=A0 Then the proc pi= cks one product_id from the queue (using delete and capturing the data deleted data using RETURNING), processes it, then loops for the next product, terminating when there are none.=C2=A0 A separate job runs to add new products needing processing to the queue table.=C2=A0 This technique allows you to run as many simultaneous jobs as you need to go through all of the products in a timely manner without code changes.=C2=A0 Also, if one fails, the others will pick up the slack since they all run until the queue is empty.=C2=A0 I've used this technique before (although not in Postgres) and it works well.


On 12/8/24 10:26 AM, David G. Johnston wrote:
On Sunday, December 8, 2024, kunwar singh <krishsingh.111@gmail.com> wrote:

= I know I can create a bash script or Python script , but I am wondering if= there is a smarter way to do it in Postgres?


Your concurrency requirement makes doing it in the server quite difficult.=C2=A0 Using anything that can launch multiple processes/threads and initiate one connect each is your best option.=C2=A0 Many things can, so pick one you are familiar with.= =C2=A0 There is little complexity here that specialized tooling would be needed for.

David J.=C2=A0