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 1i9zOw-0004V1-Fk for pgsql-general@arkaria.postgresql.org; Mon, 16 Sep 2019 22:23:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i9zOv-00081f-6u for pgsql-general@arkaria.postgresql.org; Mon, 16 Sep 2019 22:23:17 +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 1i9zOu-00081R-TV for pgsql-general@lists.postgresql.org; Mon, 16 Sep 2019 22:23:16 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i9zOn-00054P-Df for pgsql-general@lists.postgresql.org; Mon, 16 Sep 2019 22:23:16 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 5052E215B2; Mon, 16 Sep 2019 18:23:08 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 16 Sep 2019 18:23:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=6 ZFW1JBRoiG2+kkO8uxFWBqPKwLVIhgN7DeCVqUZ7oQ=; b=KsO7CisS2a9J7kNIz Hbf6sfealpuCvSf0DrR8OsmuMmO3b/gd6TIh2quOKvjb/OuFoeup39rEBK+8H/tO RuUjdI0qCR+q79IX+LiKKHppopNHxqU3rnT0NsZbfcfJwY4PlA5T8Czsa5g7+1Wx dN59QlCJpbiUpEwW+tkEn340DKpZOdvRvz+tR7u6jNFBrkGpz5YRlXg7e/kteXvH CUNNCf/Gke+xH505v6EePjZsySsE2lYFUBdGDuBgZC0QzMB4ikyqSXuA0ApC8mPn +o5fNhnud5ncgK2iLjNepJVFXp2VUQXQP//a8emCwrgubEj1t38ffYK893o1KzaU wc71g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=fm3; bh=6ZFW1JBRoiG2+kkO8uxFWBqPKwLVIhgN7DeCVqUZ7 oQ=; b=ia2oRJwE6K/dK52xk269eep0CMTuPqK4zkyPFaLO5BMJ8bZQ+VUV4CFXe Ung6j+AaHy6MPbkJfeMuGA/+9RKsRfxzXes+JasV/zxUPXqyXd84ilTcbhypCf1r xYIVSynRRRWiDMJ0z6BghzfbdJl3JDNYOvXET79Ywmrpnt/19cCsihTLLucf7661 cGkumKqYZqzrRKv7b+XAz5GBy6F9QDJd/ouFNosAlAChrza+M4EgMq51bS89unk/ aID+TDWNlDYv9qEcP7hhb/kNYdG59FDPMLVsAXWrGhhJCMvN9En4Sm47+sTSMMVY iBmJlcwWEt5JOuCvWp5zwTxstfJfg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudeggddutdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughrihgr nhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh eqnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrghenucfkphephedtrdduleej rdektddrvdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrh esrghklhgrvhgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from ranger.suse (50-197-80-2-static.hfc.comcastbusiness.net [50.197.80.2]) by mail.messagingengine.com (Postfix) with ESMTPA id 7128AD60057; Mon, 16 Sep 2019 18:23:07 -0400 (EDT) Subject: Re: Dubugging an intermittent foreign key insert error with csvlog To: Jeff Ross , pgsql-general@lists.postgresql.org References: <750a7274-384c-b52f-1b9f-d1c13bfe112b@aklaver.com> From: Adrian Klaver Message-ID: Date: Mon, 16 Sep 2019 15:23:06 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.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 9/16/19 3:16 PM, Jeff Ross wrote: > On 9/16/19 4:07 PM, Adrian Klaver wrote: >> On 9/16/19 1:46 PM, Jeff Ross wrote: > >>> >>> The csvlog snip shows what I believe are 2 simultaneous but separate >>> sessions and the session that attempts to insert into the cargo_det >>> table is not the same session that inserted into the load_det table. >>> That's what my hunch is but what is unclear to me is if those >>> separate sessions are also in separate transactions. >> >> To me it looks like the INSERT into load_det and into cargo_det are >> occurring in the same transaction(934281062). The part that would >> concern me is that: >> >> select last_value from load_det_id_seq >> >> occurs in different transactions and sessions. From here: >> >> https://www.postgresql.org/docs/11/sql-createsequence.html >> >> "Also, last_value will reflect the latest value reserved by any >> session, whether or not it has yet been returned by nextval." >> >> Especially as the error is coming from a different >> transaction(934281063) and session then the INSERTs. I'm guessing that >> there is cross talk on the sequence number fetch and application to >> cargo_det. >> > > Thank you Adrian--I think my hunch was basically correct then.  Now all > I need to do is figure out why we have multiple sessions and > transactions.  Or it might be time to skip ahead and get rid of the > last_value query. Yes, RETURNING makes this sort of thing so much easier it pays to invest the time in making it part of the query. > > Jeff > > -- Adrian Klaver adrian.klaver@aklaver.com