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.92) (envelope-from ) id 1jGAfj-0002YA-4b for pgsql-general@arkaria.postgresql.org; Mon, 23 Mar 2020 00:10:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jGAff-0006W8-Cm for pgsql-general@arkaria.postgresql.org; Mon, 23 Mar 2020 00:10:23 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1jGAff-0006Ty-2P for pgsql-general@lists.postgresql.org; Mon, 23 Mar 2020 00:10:23 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jGAfW-0001vt-C9 for pgsql-general@lists.postgresql.org; Mon, 23 Mar 2020 00:10:22 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 6674C5C01CF; Sun, 22 Mar 2020 20:10:11 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sun, 22 Mar 2020 20:10:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=e 2SFZfJk99t/t8BnO8dOSXcUIaYm6ljEU/S3Lf+/1VU=; b=vRG83mGHDvRUc8jAW vDDmkVDQbesOjlsRb7fPt6JfaqLLR7V4b96cTdhmsC1A7xhCewlF8GjOF1zI4M+R 8W80ztJyvjMJhdk0jJ8jGppcjHXp1FibuXlQRiVWzX0KGj7ixtJnbeYdYGDMrdd0 wJgcEKV+mqKAaM4RsQzEaQ+1Ge2ugr0B4WnbFSerl5hfPGoQJx+24bxvNbipCkb3 XmNsoKpAxqcSmWdMhNkmIktfGLTWBiJEnfgh7/D2Bu+AivbbB20V+UxjzRulAT1f uFIqr+Tpt6x1bgWVqZLTmcFiDAoYWsxXOIqdGCemF0GAGRGRfe1uWg0Pr8o96ptc n5JDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=e2SFZfJk99t/t8BnO8dOSXcUIaYm6ljEU/S3Lf+/1 VU=; b=0Oq+ZxVAViXe43PqNr0c6HaNkDrkoKl3TjtsGE0XgAVj/2KTLDGKyknaS rQZBBtOeke8tHrDVEJU21lpW2RandL8jbxqfpsPGYe7BoazKxfFiIfH3GrDN1fUw pQo4/bqMmsCE8JCR8r31U54OevL/U+9fwwlo7yiNWeQhL5qY5HJpivrZ5BNVQWXt EfFDKcITA8pRgQfCVcssViYUb9SdSq/TiX9dMTI17ghCWKx3UMBfe+quq8kEl6Y7 2ArdqdOXSLGFFo+9iufF7IZXjKnQG6pFtFg9vzc1zt5uDaQpPLNeEZAk04pR5G6T ltKTUTt5397o1Bu0kL/+fY2qx3neA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrudegjedgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtke ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuffhomhgrihhnpehgihhthhhusgdrtg homhenucfkphepjedurddvuddvrdduvdelrdduleefnecuvehluhhsthgvrhfuihiivgep tdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklh grvhgvrhdrtghomh X-ME-Proxy: Received: from [192.168.1.10] (unknown [71.212.129.193]) by mail.messagingengine.com (Postfix) with ESMTPA id AA7FA3062A4E; Sun, 22 Mar 2020 20:10:10 -0400 (EDT) Subject: Re: Duplicate key violation on upsert To: Matt Magoffin Cc: pgsql-general@lists.postgresql.org References: <0E4E069D-40B1-46C1-9BA0-5A5E737F753B@msqr.us> <604644e7-6881-3fdb-8767-897fc40559ac@aklaver.com> <03EC7E36-EA7F-452A-B0A9-2F0FBB73E914@msqr.us> <00a020ca-f2db-2dd7-2aa6-e3ef78e7ba68@aklaver.com> <162ae0d1-be71-f200-2b58-80b4b955fea8@aklaver.com> <80cdd870-e46c-147a-d063-03acfb30c892@aklaver.com> From: Adrian Klaver Message-ID: Date: Sun, 22 Mar 2020 17:10:10 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 3/22/20 2:48 PM, Matt Magoffin wrote: > >> On 23/03/2020, at 9:44 AM, Adrian Klaver > > wrote: >> Is there a chance the BEFORE trigger functions are doing something >> that could be leading to the error? >> >> In the error log is there a line with the actual values that failed? > > The error log does not show the literal values, no. Here is a literal > example from the logs: > > 2020-03-20 19:51:11 NZDT [15165]: [6-1] ERROR:  duplicate key value > violates unique constraint "_hyper_1_1931_chunk_da_datum_x_acc_idx" > 2020-03-20 19:51:11 NZDT [15165]: [7-1] CONTEXT:  SQL statement "INSERT > INTO solardatum.da_datum(ts, node_id, source_id, posted, jdata_i, > jdata_a, jdata_s, jdata_t) >                 VALUES (ts_crea, node, src, ts_post, jdata_json->'i', > jdata_json->'a', jdata_json->'s', > solarcommon.json_array_to_text_array(jdata_json->'t')) >                 ON CONFLICT (node_id, ts, source_id) DO UPDATE >                 SET jdata_i = EXCLUDED.jdata_i, >                         jdata_a = EXCLUDED.jdata_a, >                         jdata_s = EXCLUDED.jdata_s, >                         jdata_t = EXCLUDED.jdata_t, >                         posted = EXCLUDED.posted >                 RETURNING (xmax = 0)" >         PL/pgSQL function solardatum.store_datum(timestamp with time > zone,bigint,text,timestamp with time zone,text,boolean) line 10 at SQL > statement > 2020-03-20 19:51:11 NZDT [15165]: [8-1] STATEMENT:  select * from > solardatum.store_datum($1, $2, $3, $4, $5) as result So the query is in the function solardatum.store_datum()? If so what is it doing? And could you capture the values and pass them to a RAISE NOTICE? > > As for the BEFORE triggers, the solardatum.trigger_agg_stale_datum one > does an INSERT into a different table and a SELECT from this same table. > The _timescaledb_internal.insert_blocker one is part of the TimescaleDB > extension which looks like it wouldn’t have an impact to this issue, but > the source of that is > > https://github.com/timescale/timescaledb/blob/91fe723d3aaaf88b53ffffebf8adc3e16a68ec45/src/hypertable.c#L1359 > > — m@ -- Adrian Klaver adrian.klaver@aklaver.com