From: Rui DeSousa <rui.desousa@icloud.com>
To: Corey Taylor <corey.taylor.fl@gmail.com>
Cc: Melvin Davidson <melvin6925@gmail.com>
Cc: Peter Geoghegan <pg@bowt.ie>
Cc: Luis Marin <luismarinaray@gmail.com>
Cc: pgsql-admin@postgresql.org, pgsql-general General <pgsql-general@postgresql.org>
Subject: Re: Ideas to deal with table corruption
Date: Sat, 06 Jan 2018 14:59:04 -0500
Message-ID: <75A0F4D4-2A34-497F-82F9-C04D436F4FF8@icloud.com> (raw)
In-Reply-To: <CADBz387cdv6JgKt7PqJa=6Lf7dVepq+DMpi5=m_tijJHS=RNmA@mail.gmail.com>
References: <CAEp6HQXseuvaU_UGOju3rMduhHB+QTYcZa5oda+_82eQ73DVtw@mail.gmail.com>
<CAH2-WzmpkQo+YaGTDoWQ600HdN5NqJtwA=puDqG0tVa+9PhsWw@mail.gmail.com>
<CANu8FiyXAZQVCd2uDY1T9acVThFRSTgYZgZFBZaOZtSTuWif2g@mail.gmail.com>
<CADBz387cdv6JgKt7PqJa=6Lf7dVepq+DMpi5=m_tijJHS=RNmA@mail.gmail.com>
Correct, and there is no need to create an index on a unique constraint or primary key as they are already implemented via indexes. I can’t count how many duplicate indexes I’ve dropped in the past. I use this view help find duplicates in a given system. Duplicate indexes just use up space and rob performance during updates and inserts.
/*======================================================================================================
q$Id: duplicate_index.sql 1 2015-12-19 15:40:29Z rui $
Description: Find duplicate indexes
======================================================================================================*/
create or replace view duplicate_index
as
select base.indrelid::regclass as table_name
, string_agg((dup.indexrelid::regclass)::text, E'\n') as indexes
, pg_size_pretty(avg(pg_relation_size(dup.indexrelid))) as avg_size
from pg_index base
join pg_index dup on dup.indrelid = base.indrelid -- table identifier
and dup.indkey = base.indkey -- columns indexed
and dup.indclass = base.indclass -- columns types
and (
dup.indexprs = base.indexprs -- expression predicate for columns
or (
dup.indexprs is null
and base.indexprs is null
)
)
and (
dup.indpred = base.indpred -- expression predicate for where clause
or (
dup.indpred is null
and base.indpred is null
)
)
and dup.indexrelid != base.indexrelid --index identifier
group by base.indrelid::regclass
, concat(base.indkey::text, base.indclass::text, base.indexprs, base.indpred)
order by avg_size desc
, base.indrelid::regclass
;
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-admin@postgresql.org
Cc: rui.desousa@icloud.com, corey.taylor.fl@gmail.com, melvin6925@gmail.com, pg@bowt.ie, luismarinaray@gmail.com, pgsql-general@postgresql.org
Subject: Re: Ideas to deal with table corruption
In-Reply-To: <75A0F4D4-2A34-497F-82F9-C04D436F4FF8@icloud.com>
References: <CAEp6HQXseuvaU_UGOju3rMduhHB+QTYcZa5oda+_82eQ73DVtw@mail.gmail.com> <CAH2-WzmpkQo+YaGTDoWQ600HdN5NqJtwA=puDqG0tVa+9PhsWw@mail.gmail.com> <CANu8FiyXAZQVCd2uDY1T9acVThFRSTgYZgZFBZaOZtSTuWif2g@mail.gmail.com> <CADBz387cdv6JgKt7PqJa=6Lf7dVepq+DMpi5=m_tijJHS=RNmA@mail.gmail.com> <75A0F4D4-2A34-497F-82F9-C04D436F4FF8@icloud.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