From: hubert depesz lubaczewski <depesz@depesz.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: Thu, 18 Aug 2022 11:00:44 +0200
Message-ID: <20220818090044.GB12228@depesz.com> (raw)
In-Reply-To: <CAA3DN=XSaPuxpGhznP_rNJz_AGdMFHeGXVvPt4TbwZsfrGD7fg@mail.gmail.com>
References: <CAA3DN=XSaPuxpGhznP_rNJz_AGdMFHeGXVvPt4TbwZsfrGD7fg@mail.gmail.com>
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
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: depesz@depesz.com, aqoyyuum@cardaccess.com.au
Subject: Re: Unable to Create or Drop Index Concurrently
In-Reply-To: <20220818090044.GB12228@depesz.com>
References: <CAA3DN=XSaPuxpGhznP_rNJz_AGdMFHeGXVvPt4TbwZsfrGD7fg@mail.gmail.com> <20220818090044.GB12228@depesz.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