pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Noel Jones <nparker@apexfintechsolutions.com>
To: pgsql-general@lists.postgresql.org
Cc: Omar Arain <oarain@apexfintechsolutions.com>
Subject: Re: Invalid Parent Index Issue Will Not Resolve Despite Multiple Attempts To Fix
Date: Fri, 08 Dec 2023 05:26:34 +0100
Message-ID: <f1c76688f9e14025282810fee91bd047e34ed6ed.camel@cybertec.at> (raw)
In-Reply-To: <CA+8TBoK9Agztv1WLexm2Nr7sY8ygpnN8K_XE=qSKCiD0zC20bA@mail.gmail.com>
References: <CA+8TBoK9Agztv1WLexm2Nr7sY8ygpnN8K_XE=qSKCiD0zC20bA@mail.gmail.com>

On Thu, 2023-12-07 at 16:38 -0600, Noel Jones wrote:
> We have been utilizing partitioned tables with indexes. We've recently had an issue
> where the parent table's index (id, date) became invalid (indisvalid=FALSE,
> indisready=FALSE in pg_index). For reference the parent table is partitioned on a
> date field within the table.

Indexes don't become invalid just so.  I wonder what happened.

> We attempted to fix the issue by doing the following:
> 
> ALTER TABLE table_parent DETACH PARTITION table_badpartition;
> DROP INDEX brokenchildindex;
> CREATE INDEX newchildindex on table_badpartition using btree (id, date);
> ALTER TABLE table_parent ATTACH PARTITION table_badpartition
> FOR VALUES FROM (date) TO (date+1);
> 
> This did not fix the issue  so we attempted an alternate fix:
> 
> begin;
> set role readwrite;
> ALTER TABLE table_parent DETACH PARTITION table_badpartition;
> ALTER TABLE table_badpartition RENAME TO table_badpartition_detached;
> CREATE TABLE table_badpartition PARTITION OF table_parent
> FOR VALUES FROM (date) TO (date+1);
> ALTER TABLE table_badpartitioneplica identity full;
> INSERT INTO table_badpartition (id, date, ...)
> SELECT id, date, ... from table_badpartition_detached;
> commit;
> 
> This new table was created with the correct columns, the accurate data, and the
> correct indices  however the parent index is still listed with indisvalid = FALSE
> and indisready = FALSE.

You forgot to ALTER INDEX ... ATTACH PARTITION to turn the invalid index on the
partitioned table into a valid index.

Yours,
Laurenz Albe





view thread (3+ messages)  latest in thread

Message-ID: <f1c76688f9e14025282810fee91bd047e34ed6ed.camel@cybertec.at>
Permalink:  ../f1c76688f9e14025282810fee91bd047e34ed6ed.camel@cybertec.at/
Also on:    postgresql.org/message-id/f1c76688f9e14025282810fee91bd047e34ed6ed.camel@cybertec.at

 · 

reply

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: laurenz.albe@cybertec.at, nparker@apexfintechsolutions.com, oarain@apexfintechsolutions.com
  Subject: Re: Invalid Parent Index Issue Will Not Resolve Despite Multiple Attempts To Fix
  In-Reply-To: <f1c76688f9e14025282810fee91bd047e34ed6ed.camel@cybertec.at>
  References: <CA+8TBoK9Agztv1WLexm2Nr7sY8ygpnN8K_XE=qSKCiD0zC20bA@mail.gmail.com> <f1c76688f9e14025282810fee91bd047e34ed6ed.camel@cybertec.at>

* 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