Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hwSHF-0002zA-Tu for pgsql-bugs@arkaria.postgresql.org; Sat, 10 Aug 2019 14:23:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hwSHC-0006AB-Sb for pgsql-bugs@arkaria.postgresql.org; Sat, 10 Aug 2019 14:23:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hwSHC-00069z-I5 for pgsql-bugs@lists.postgresql.org; Sat, 10 Aug 2019 14:23:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1hwSH9-0000zs-Al for pgsql-bugs@lists.postgresql.org; Sat, 10 Aug 2019 14:23:20 +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 x7AENGnL000619; Sat, 10 Aug 2019 10:23:16 -0400 From: Tom Lane To: ladayaroslav@yandex.ru cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15946: "duplicate key" error on ANALYZE of table partitions in transaction In-reply-to: <15946-5c7570a2884a26cf@postgresql.org> References: <15946-5c7570a2884a26cf@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Sat, 10 Aug 2019 12:45:26 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <617.1565446996.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 10 Aug 2019 10:23:16 -0400 Message-ID: <618.1565446996@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > Running this: > ... > Throws this error: > ERROR: duplicate key value violates unique constraint "pg_statistic_rel= id_att_inh_index" > DETAIL: Key (starelid, staattnum, stainherit)=3D(61056, 1, f) already e= xists. Hm, you don't need all the fancy partitioning stuff: regression=3D# create table t as select generate_series(1,10) x; SELECT 10 regression=3D# begin; BEGIN regression=3D# analyze t, t; ERROR: duplicate key value violates unique constraint "pg_statistic_relid= _att_inh_index" DETAIL: Key (starelid, staattnum, stainherit)=3D(35836, 1, f) already exi= sts. It appears to work fine without the BEGIN: regression=3D# analyze t, t; ANALYZE but then regression=3D# begin; BEGIN regression=3D# analyze t, t; ERROR: tuple already updated by self I think the conclusion is that if we aren't using per-table transactions we'd better do a CommandCounterIncrement between tables in vacuum()'s loop. regards, tom lane