pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Jeff Ross <jross@openvistas.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: Dubugging an intermittent foreign key insert error with csvlog
Date: Mon, 16 Sep 2019 15:23:06 -0700
Message-ID: <c59e0bb6-2776-9c73-1c2a-84866974fb10@aklaver.com> (raw)
In-Reply-To: <a709e513-fd5e-8a4c-5279-5227e09af346@openvistas.net>
References: <e5c66bff-9b66-13a8-b88c-99fae49318f4@openvistas.net>
	<750a7274-384c-b52f-1b9f-d1c13bfe112b@aklaver.com>
	<a709e513-fd5e-8a4c-5279-5227e09af346@openvistas.net>

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





view thread (4+ messages)

Message-ID: <c59e0bb6-2776-9c73-1c2a-84866974fb10@aklaver.com>
Permalink:  ../c59e0bb6-2776-9c73-1c2a-84866974fb10@aklaver.com/
Also on:    postgresql.org/message-id/c59e0bb6-2776-9c73-1c2a-84866974fb10@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, jross@openvistas.net
  Subject: Re: Dubugging an intermittent foreign key insert error with csvlog
  In-Reply-To: <c59e0bb6-2776-9c73-1c2a-84866974fb10@aklaver.com>
  References: <e5c66bff-9b66-13a8-b88c-99fae49318f4@openvistas.net> <750a7274-384c-b52f-1b9f-d1c13bfe112b@aklaver.com> <a709e513-fd5e-8a4c-5279-5227e09af346@openvistas.net> <c59e0bb6-2776-9c73-1c2a-84866974fb10@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox