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 1sWMBW-00Efkq-1I for pgsql-general@arkaria.postgresql.org; Tue, 23 Jul 2024 20:32:33 +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 1sWMBT-00GGK7-IY for pgsql-general@arkaria.postgresql.org; Tue, 23 Jul 2024 20:32:31 +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 1sWMBT-00GGJy-7v for pgsql-general@lists.postgresql.org; Tue, 23 Jul 2024 20:32:31 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sWMBR-00173B-Dw for pgsql-general@lists.postgresql.org; Tue, 23 Jul 2024 20:32:31 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 46NKWRvR1085897; Tue, 23 Jul 2024 16:32:27 -0400 From: Tom Lane To: Ron Johnson cc: pgsql-general Subject: Re: Issue while creating index dynamically In-reply-to: References: Comments: In-reply-to Ron Johnson message dated "Tue, 23 Jul 2024 16:20:59 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1085895.1721766747.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Tue, 23 Jul 2024 16:32:27 -0400 Message-ID: <1085896.1721766747@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Ron Johnson writes: > On Tue, Jul 23, 2024 at 4:10 PM veem v wrote: >> But we are getting an error while executing saying it cant be executed in >> transaction block with "CONCURRENTLY". So I want to understand , is there >> any alternate way to get away with this? > I'd write that in bash, not in a DO block. Yeah. I thought for a bit about using contrib/dblink to carry out the commands in a different session, but I don't think that'll work: CREATE INDEX CONCURRENTLY would think it has to wait out the transaction running the DO block at some steps. Shove the logic over to the client side and you're good to go. regards, tom lane