From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Matt Magoffin <postgresql.org@msqr.us>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Duplicate key violation on upsert
Date: Sun, 22 Mar 2020 17:10:10 -0700
Message-ID: <ff653668-3fad-da5c-b26a-addd2ea0f87e@aklaver.com> (raw)
In-Reply-To: <DDC9F7A4-4145-4DDD-BBC4-06D931DA7BE0@msqr.us>
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>
<C6A3AA75-38FA-4A8E-9FBD-A9121AE4EE91@msqr.us>
<a7aecaad-5bb5-3daf-95e8-2c815039f66c@aklaver.com>
<162ae0d1-be71-f200-2b58-80b4b955fea8@aklaver.com>
<EB9192B4-9EAC-4376-BC8B-5D9CEF56F5FE@msqr.us>
<80cdd870-e46c-147a-d063-03acfb30c892@aklaver.com>
<DDC9F7A4-4145-4DDD-BBC4-06D931DA7BE0@msqr.us>
On 3/22/20 2:48 PM, Matt Magoffin wrote:
>
>> On 23/03/2020, at 9:44 AM, Adrian Klaver <adrian.klaver@aklaver.com
>> <mailto:adrian.klaver@aklaver.com>> 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/hypertabl...
>
> — m@
--
Adrian Klaver
adrian.klaver@aklaver.com
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, postgresql.org@msqr.us
Subject: Re: Duplicate key violation on upsert
In-Reply-To: <ff653668-3fad-da5c-b26a-addd2ea0f87e@aklaver.com>
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> <C6A3AA75-38FA-4A8E-9FBD-A9121AE4EE91@msqr.us> <a7aecaad-5bb5-3daf-95e8-2c815039f66c@aklaver.com> <162ae0d1-be71-f200-2b58-80b4b955fea8@aklaver.com> <EB9192B4-9EAC-4376-BC8B-5D9CEF56F5FE@msqr.us> <80cdd870-e46c-147a-d063-03acfb30c892@aklaver.com> <DDC9F7A4-4145-4DDD-BBC4-06D931DA7BE0@msqr.us> <ff653668-3fad-da5c-b26a-addd2ea0f87e@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