From: Christophe Pettus <xof@thebuild.com>
To: Abdul Qoyyuum <aqoyyuum@cardaccess.com.au>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Unable to Create or Drop Index Concurrently
Date: Wed, 17 Aug 2022 23:05:19 -0700
Message-ID: <39C326BF-3E02-42CD-90DB-3B56BC9A09CE@thebuild.com> (raw)
In-Reply-To: <CAA3DN=XSaPuxpGhznP_rNJz_AGdMFHeGXVvPt4TbwZsfrGD7fg@mail.gmail.com>
References: <CAA3DN=XSaPuxpGhznP_rNJz_AGdMFHeGXVvPt4TbwZsfrGD7fg@mail.gmail.com>
> On Aug 17, 2022, at 22:57, Abdul Qoyyuum <aqoyyuum@cardaccess.com.au> 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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: xof@thebuild.com, aqoyyuum@cardaccess.com.au
Subject: Re: Unable to Create or Drop Index Concurrently
In-Reply-To: <39C326BF-3E02-42CD-90DB-3B56BC9A09CE@thebuild.com>
References: <CAA3DN=XSaPuxpGhznP_rNJz_AGdMFHeGXVvPt4TbwZsfrGD7fg@mail.gmail.com> <39C326BF-3E02-42CD-90DB-3B56BC9A09CE@thebuild.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox