Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eJgmo-0003wU-A0 for pgsql-general@arkaria.postgresql.org; Tue, 28 Nov 2017 14:22:58 +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 1eJgmn-00068s-30 for pgsql-general@arkaria.postgresql.org; Tue, 28 Nov 2017 14:22:57 +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 1eJgmm-00068i-RT for pgsql-general@lists.postgresql.org; Tue, 28 Nov 2017 14:22:56 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eJgmi-0002pj-Gs for pgsql-general@postgresql.org; Tue, 28 Nov 2017 14:22:56 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id vASEMmfH013147; Tue, 28 Nov 2017 09:22:48 -0500 From: Tom Lane To: Swapnil Vaze cc: pgsql-general@postgresql.org Subject: Re: vacuumdb fails with error pg_statistic_relid_att_inh_index constraint violation after upgrade to 9.6 In-reply-to: References: Comments: In-reply-to Swapnil Vaze message dated "Tue, 28 Nov 2017 18:55:20 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <13145.1511878968.1@sss.pgh.pa.us> Date: Tue, 28 Nov 2017 09:22:48 -0500 Message-ID: <13146.1511878968@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Swapnil Vaze writes: > We have upgraded our database from 9.5 to 9.6 version. > After upgrade we ran vacuumdb command and we are getting following error: > vacuumdb: vacuuming of database "advdfat" failed: ERROR: duplicate key > value violates unique constraint "pg_statistic_relid_att_inh_index" > DETAIL: Key (starelid, staattnum, stainherit)=(1259, 1, f) already exists. Hmm, odd. > Can anyone help here? In order of increasing invasiveness: 1. REINDEX pg_statistic_relid_att_inh_index, on the theory that that index has become corrupt. 2. If #1 fails with a similar message, there must actually be more than one pg_statistic row with that key. Manually DELETE those rows, then REINDEX the index, then ANALYZE pg_class to regenerate the deleted stats. (I suggest reindexing because this case makes it even more likely that that index is corrupt.) 3. If #2 fails, TRUNCATE pg_statistic, then re-analyze everything to rebuild the stats. regards, tom lane