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 1oObOW-0004q8-RH for pgsql-general@arkaria.postgresql.org; Thu, 18 Aug 2022 09:00:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oObOV-0000gC-QB for pgsql-general@arkaria.postgresql.org; Thu, 18 Aug 2022 09:00:51 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oObOV-0000g2-Ej for pgsql-general@lists.postgresql.org; Thu, 18 Aug 2022 09:00:51 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oObOS-0006XC-7k for pgsql-general@lists.postgresql.org; Thu, 18 Aug 2022 09:00:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Type:MIME-Version:References:Reply-To: Message-ID:Subject:Cc:To:Sender:From:Date:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=xMF8dF//BWuIIgduAhawMOeHa+ozj5Q4zDXU0LO8MfU=; b=LriuzqtHZGoyYLKJZt+h8z2ze4 b2nbOjse55us7dqmInrTDETcAX1x14OKCdcSiCrbQDx7W7qfTnwUHCyZxCW6JnTRp5iN9ZabQ+z6x niZNBy9hYfhKo4tcT1VbjklVgxGc+Jt8ILl9V4bvfIOGID9NoUXzYglKquj5RMGVprUg=; Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by depesz.com with esmtpa (Exim 4.92) (envelope-from ) id 1oObOO-0004m3-PO; Thu, 18 Aug 2022 11:00:44 +0200 Date: Thu, 18 Aug 2022 11:00:44 +0200 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: Abdul Qoyyuum Cc: "pgsql-generallists.postgresql.org" Subject: Re: Unable to Create or Drop Index Concurrently Message-ID: <20220818090044.GB12228@depesz.com> Reply-To: depesz@depesz.com References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Aug 18, 2022 at 01:57:48PM +0800, Abdul Qoyyuum wrote: > Hi list, > > We have a running Master-Slave High Availability set up. Naturally, we > can't run any changes on read-only databases on slave, so we have to do it > on the master node. > > When trying to run the following command: > > create index concurrently idx_cash_deposit_channel_id_batch_id on > cash_deposit (channel_id, batch_id); > > > Waiting for a long time, and my connection dropped. When checking the > table, we get the index as INVALID > > Indexes: > "pk_cash_deposit" PRIMARY KEY, btree (id) > "idx_cash_deposit_channel_id_batch_id" btree (channel_id, batch_id) > INVALID > > And when dropping the invalid index, also takes a long time, my connection > timed out, then when logging back in and check the table, it hasn't dropped. This means that you have some very long transactions. To make/drop index concurrently, all transactions that have started before you started create/drop, have to finish. You can see your oldest transactions by doing: select * from pg_stat_activity where xact_start is not null order by xact_start Best regards, depesz