Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lHhvv-0002VJ-IH for pgsql-general@arkaria.postgresql.org; Thu, 04 Mar 2021 06:58:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lHhvu-00062w-FR for pgsql-general@arkaria.postgresql.org; Thu, 04 Mar 2021 06:58:02 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lHhvu-00062p-5s for pgsql-general@lists.postgresql.org; Thu, 04 Mar 2021 06:58:02 +0000 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lHhvs-00019K-Bn for pgsql-general@lists.postgresql.org; Thu, 04 Mar 2021 06:58:01 +0000 Received: by mail-ot1-x330.google.com with SMTP id t16so6737794ott.3 for ; Wed, 03 Mar 2021 22:58:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=HWFQcLKUnb+PSB1gSnNOHtlf5zIfUDVFc+oGMsigXTM=; b=lTrJ/4bYzoERwJhG1IlcQjsnunLNELEOQKCnonYg7T3wSBLbdu+t+kQV6y+RTTKGk4 MCXLc7MusbFvI0VqyEIBfuUKAVTdqaKyT7JJcimbfETEFhfRZGSZwfIlo4o/JEDHA4Hx O6swDymT80c/KCbzn6z5RVVKc9WSdqzUKQd6VSYTvAia9DbGG2OIM5NJ3G6+lYalm4BX 73yyOAsORPdLgDjkakg2umjgPM2UcQ0lX+17ez+23TIBt/YeptJ5NFVGOSvfKdVBVeUA 3Lv8vOaJ3w52z15qYeQPu4dGGSFdOaidgMq+zh2xLXsu9kKKYgyiG7Nc7CQbUSgMH4z/ EiVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=HWFQcLKUnb+PSB1gSnNOHtlf5zIfUDVFc+oGMsigXTM=; b=MOX7DEG7pM+zcxmQB5o3jTCqfvAMyPgtGtzqy4s8+FhvMyfEkIQuRlvVBIThDmKZ4n m3bTmhSQ5gq3Nn3l7Epngmwb80YGJHDJ7uXKemS9MCM4JW3YChJOr7ffeCZXtaSPQSO1 G87OeOK62JQ6m6r1/U6Ycgl76vSi1K7/+o+luBEY9QA1zsfzR0g7pi4hzK1xSBpHmqcU 5SgfUNMyl1upVkcl096Cu4qOW72twSUsnBaNq7UTpnYTrpsstxPBexvJfG73P8GqmjMI CncJ8+tIJUVLkrl62KTdRLLeHj1tLll6y/caiH9+dMHIbzJg2wM7aUAYvPBmCGPWq/ca VWng== X-Gm-Message-State: AOAM5317vN89l5Hegf/KjGAC8YR+KBpWTJ7lL9fc51Mh4t0IhVlhHZIH dlU9ZpeYF/w2mcfJJim5cf0JB8irqgjeZg== X-Google-Smtp-Source: ABdhPJyW19DkG8xsE3pmgH4vJMOhYF8azTecbxwzxvzatnyyq7X3w4cORl6IX5f7azQ1diyc1lzqlw== X-Received: by 2002:a05:6830:1057:: with SMTP id b23mr2515254otp.206.1614841079378; Wed, 03 Mar 2021 22:57:59 -0800 (PST) Received: from [192.168.88.10] (ip174-67-141-204.no.no.cox.net. [174.67.141.204]) by smtp.googlemail.com with ESMTPSA id s11sm1135122oia.33.2021.03.03.22.57.58 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Mar 2021 22:57:58 -0800 (PST) Subject: Re: Duplicate key error To: pgsql-general@lists.postgresql.org References: <5b68b4b3-b957-5009-cf3e-4bbc9dcbd0d9@aklaver.com> <97577cda-b3fa-4edb-1c8a-2b39afad65c6@hot.ee> <6a9dcf88-7b28-3b8f-0a1a-8a163f45a2a8@hot.ee> From: Ron Message-ID: <19beef53-95f4-672a-deda-41e236b03e38@gmail.com> Date: Thu, 4 Mar 2021 00:57:57 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <6a9dcf88-7b28-3b8f-0a1a-8a163f45a2a8@hot.ee> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/4/21 12:14 AM, Andrus wrote: > Hi! >> says something else is inserting/updating using that key value. So >> obviously your script is not catching all the conflicts. > > > At this point your best bet is to monitor the Postgres log and see what > else is happening at the time of the error. I'm guessing you will find > another process working on that table. > > It looks like other process has added same row during trancaction. > > How to change script so that it works starting at Postgres 9.0 and does > not cause error in this case ? > Having all the processes which try to update that table explicitly set a serializable transaction would probably eliminate the duplicate key error.  There's no free lunch, though: you'd have to handle the blocking. -- Angular momentum makes the world go 'round.