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 1jHK7s-0005co-6L for pgsql-general@arkaria.postgresql.org; Thu, 26 Mar 2020 04:28:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jHK7q-0008I1-Vh for pgsql-general@arkaria.postgresql.org; Thu, 26 Mar 2020 04:28:14 +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 1jHK7p-0008Ht-M7 for pgsql-general@lists.postgresql.org; Thu, 26 Mar 2020 04:28:14 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jHK7i-0006Tx-Fw for pgsql-general@lists.postgresql.org; Thu, 26 Mar 2020 04:28:12 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id BDCC7578; Thu, 26 Mar 2020 00:28:04 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 26 Mar 2020 00:28:04 -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=3 51yFPRSYn/vUmrc+RFi2DHPm4ldrW4tNubj92zmOac=; b=i9uB0no3XQHvGkun5 E1teouDOje5DAikpk8foXjO6dLiWScaC5LKsOB14Hu9jto+LDWuMLz4o2WCp7YE9 htg2TYqb08KeLjAI4g+z2VKRLe40R4GNxcQCkezXB3F5oJAUlioemk3FFYvJGAEQ uiJkUgelOUAQm0tYovY7q/jpqKsMgaOtSKghyWsx06cVEawjxR0295NlVp5nPzx0 Eb89UjauLYHvTw8C98b4LyeiBIjNfSPlGBEgFNE3crCl5m9q8IVJ5C+KGr4FUDC5 iR0DElvAL8B2HPFAXshSacEFftzHFbEPdToi8lwdkbDo0wJ22hWy+/ajp6yhLd05 eLxXw== 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=351yFPRSYn/vUmrc+RFi2DHPm4ldrW4tNubj92zmO ac=; b=ozKWIOk0f4FYFPXwCPXXfExVR+N5vJ40dorkLmDbCamx7BwjyO9YC1Bwh u3Pz37askfktbBV6HhGjdBYFAYo5+ub3S1DG6r7dJl6RT4D1AVitlNgGpeSp/TmH a9VJ5GiCHhhyamqM/OgK+xEImo/JVa8MHZaRj/Pbk6OJp89MoJBRU0HvttH4kxJn IeYvABHi+QZRBmXptNqQ+lYmLk4vy9WOoVjHsPlcRgTi7NIDD0mJ29hTF6d/YvYn ELjXMdEPktaA0B2LJa7Gya3wygaJs/NmO/Xh8DxtGmAg9YPXkymqJmhlIRs6UqE8 BJyUzYhD40U+/H41/B524CwhueIXQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrudehhedgieekucetufdoteggodetrfdotf 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 AEF09306885A; Thu, 26 Mar 2020 00:28:03 -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> <65AECD9A-CE13-4FCB-9158-23BE62BB65DD@msqr.us> From: Adrian Klaver Message-ID: <4372965a-188b-592c-8f08-92065f90efb7@aklaver.com> Date: Wed, 25 Mar 2020 21:28:02 -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: <65AECD9A-CE13-4FCB-9158-23BE62BB65DD@msqr.us> 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/25/20 5:23 PM, Matt Magoffin wrote: > >> On 23/03/2020, at 1:10 PM, Adrian Klaver > > wrote: >> >> So the query is in the function solardatum.store_datum()? >> >> If so what is it doing? > > Yes. This function first performs the INSERT INTO the > solardatum.da_datum table that we’re discussing here; then it inserts > into two different tables. If it helps, the actual SQL is available here: > > https://github.com/SolarNetwork/solarnetwork-central/blob/4fa585929a5526187ade0e842c809837647c6a41/solarnet-db-setup/postgres/postgres-init-generic-datum-x-functions.sql#L203-L242 I told see anything wrong at first glance, but is getting late here. I will take another look in the morning. > >> And could you capture the values and pass them to a RAISE NOTICE? > > It would take me some time to get that change deployed. If I was able > to, what information do you think would be helpful here, e.g. that > jdata_a is NULL or not, or something else? The values for (node_id, ts, source_id, jdata_a) as they compromise the UNIQUE values for da_datum_pkey and da_datum_x_acc_idx. > > The duplicate key violation occurs infrequently, and it does seem > appropriate to drop the UNIQUE constraint on the da_datum_x_acc_idx > given uniqueness is really only wanted on (node_id, ts, source_id). As > long as I can confirm that query performance doesn’t decrease, I’d like > to recreate the index without UNIQUE. Then I’m hoping this problem, > whatever the cause, goes away. > > — m@ -- Adrian Klaver adrian.klaver@aklaver.com