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 1oOYes-0006Mo-KL for pgsql-general@arkaria.postgresql.org; Thu, 18 Aug 2022 06:05:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oOYeq-0006Se-IJ for pgsql-general@arkaria.postgresql.org; Thu, 18 Aug 2022 06:05:32 +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 1oOYeq-0006SV-7i for pgsql-general@lists.postgresql.org; Thu, 18 Aug 2022 06:05:32 +0000 Received: from smtp127.iad3a.emailsrvr.com ([173.203.187.127]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oOYej-000600-PW for pgsql-general@lists.postgresql.org; Thu, 18 Aug 2022 06:05:31 +0000 X-Auth-ID: xof@thebuild.com Received: by smtp24.relay.iad3a.emailsrvr.com (Authenticated sender: xof-AT-thebuild.com) with ESMTPSA id C9B17232C8; Thu, 18 Aug 2022 02:05:23 -0400 (EDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) Subject: Re: Unable to Create or Drop Index Concurrently From: Christophe Pettus In-Reply-To: Date: Wed, 17 Aug 2022 23:05:19 -0700 Cc: "pgsql-generallists.postgresql.org" X-Mailbutler-Message-Id: D2C7DC77-84AB-47A9-B246-4ADDF9EB02CD Content-Transfer-Encoding: quoted-printable Message-Id: <39C326BF-3E02-42CD-90DB-3B56BC9A09CE@thebuild.com> References: To: Abdul Qoyyuum X-Mailer: Apple Mail (2.3608.120.23.2.7) X-Classification-ID: 076485c0-eb8a-4490-b170-5ea2ecef404e-1-1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Aug 17, 2022, at 22:57, Abdul Qoyyuum = wrote: > Question is, do we have to shutdown traffic and close all existing = open connections in order to drop and properly recreate the index? No, you don't. On the CREATE INDEX CONCURRENTLY command, what is likely going on is = that when the connection drops, the session terminates, which will = terminate the CREATE INDEX CONCURRENTLY command and leave the index in = an INVALID state. The problem to solve is preventing the session from = disconnecting, either by finding a way to avoid a timeout, connecting = via screen or tmux, etc. On the DROP INDEX, what is likely going on is that the DROP INDEX is = waiting for other transactions which are accessing that table to finish, = since it needs to take an exclusive lock on the table. If the session = drops, the command isn't run, so the index hasn't been dropped. The = solution is the same as above. If you are on a version that supports = it, you can use the DROP INDEX CONCURRENTLY command to avoid locking = issues with the table, since even before the DROP INDEX happens, new = transactions attempting to access that table will queue up behind the = DROP INDEX.=