Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eXucd-00072L-Hd for pgsql-admin@arkaria.postgresql.org; Sat, 06 Jan 2018 19:59:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eXucc-0006nn-RW for pgsql-admin@arkaria.postgresql.org; Sat, 06 Jan 2018 19:59:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eXucc-0006mD-JR; Sat, 06 Jan 2018 19:59:14 +0000 Received: from mr28p48im-tydg10101201.me.com ([17.110.88.44]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eXucZ-0000Z2-5F; Sat, 06 Jan 2018 19:59:13 +0000 Received: from process-dkim-sign-daemon.mr28p48im-tydg10101201.me.com by mr28p48im-tydg10101201.me.com (Oracle Communications Messaging Server 8.0.1.2.20170607 64bit (built Jun 7 2017)) id <0P2500200GSKNX00@mr28p48im-tydg10101201.me.com>; Sat, 06 Jan 2018 19:59:07 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=04042017; t=1515268747; bh=mfrMDZrqKpuIhJc6Huf4Sk4PC1kp+wx1oT3eAY6D6BI=; h=Content-type:MIME-version:Subject:From:Date:Message-id:To; b=QyIcAuuB7Z9jqXPxGXZ2/pmYxecybUuKlqNf4luBsGBuTRvoUqbceF9UPVszibwSv yLK38hvo5OjgkEngdkuehPsOUdccCXyH8N2HNpThGw7b4ReLM7tLs71cz5AMdvMG01 wI8nbeHk5DGDz2qoWNecY5W4Nmv+w/KArqFLiX4A55lBPkSOrlqXUAXMnDyra4T9Pl BFItDYkhcPyjGLnA4yv3KqHpHCJSvAvh0k9/u4yzcS/aySqU60+4b/h7Vun++gY0wQ C0F8mMqVgKD8petx003Ydthi+/A6WPgVA311xyRVdgbLoBuUJV45Jsso1ouijSCOit hXsoQR6I1gFGw== Received: from icloud.com ([127.0.0.1]) by mr28p48im-tydg10101201.me.com (Oracle Communications Messaging Server 8.0.1.2.20170607 64bit (built Jun 7 2017)) with ESMTPSA id <0P2500JV7GUGAX00@mr28p48im-tydg10101201.me.com>; Sat, 06 Jan 2018 19:59:06 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-01-06_12:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 clxscore=1011 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1801060290 Content-type: text/plain; charset=utf-8 MIME-version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Subject: Re: Ideas to deal with table corruption From: Rui DeSousa In-reply-to: Date: Sat, 06 Jan 2018 14:59:04 -0500 Cc: Melvin Davidson , Peter Geoghegan , Luis Marin , pgsql-admin@postgresql.org, pgsql-general General Content-transfer-encoding: quoted-printable Message-id: <75A0F4D4-2A34-497F-82F9-C04D436F4FF8@icloud.com> References: To: Corey Taylor X-Mailer: Apple Mail (2.3445.5.20) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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=E2=80=99= t count how many duplicate indexes I=E2=80=99ve 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. =20 = /*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D q$Id: duplicate_index.sql 1 2015-12-19 15:40:29Z rui $ Description: Find duplicate indexes = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D*/ 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 =3D base.indrelid -- table identifier and dup.indkey =3D base.indkey -- columns indexed and dup.indclass =3D base.indclass -- columns types and ( dup.indexprs =3D base.indexprs -- expression predicate for columns or ( dup.indexprs is null=20 and base.indexprs is null ) ) =20 and ( dup.indpred =3D base.indpred -- expression predicate for where = clause or ( dup.indpred is null and base.indpred is null ) ) and dup.indexrelid !=3D 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 ;