Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fC6Qs-0008Nf-Gn for pgsql-general@arkaria.postgresql.org; Fri, 27 Apr 2018 16:41:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fC6Qq-0003li-UR for pgsql-general@arkaria.postgresql.org; Fri, 27 Apr 2018 16:41:12 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1fC6O9-0005Yj-1u for pgsql-general@lists.postgresql.org; Fri, 27 Apr 2018 16:38:25 +0000 Received: from mail-yb0-x229.google.com ([2607:f8b0:4002:c09::229]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fC6O4-0001Xl-Hj for pgsql-general@lists.postgresql.org; Fri, 27 Apr 2018 16:38:23 +0000 Received: by mail-yb0-x229.google.com with SMTP id i69-v6so832721ybg.2 for ; Fri, 27 Apr 2018 09:38:19 -0700 (PDT) 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=YdGb1ZNiyhoKEy4kbd8sOl95sJgPNMgbDxCeENyhTdA=; b=eBbUME+5ZR0t+TadwOYat3ijL05fRsQeNweQYzObeJVv4M7OIEy/hmpaIdjxFz8oXB kHYQtrQx3K74HroBp4ipfOFSC17TAkAJNTnYe/WFPviAhQ7FkQHaeBxAvcyGO18TW0dP t07v84sjAU4IyIJ6IwFOogT8SLmmOvqgik+1yYpLoyzN0hnnN0rqttCos3Zwu6xs9Jom apT2x4u58b21MQM169r5GIcoWxzFN1wXKqDiV7AzNDHujPvtjCFIPtqoaXiqVsjDidu3 eGzA0YrjMEH8NPE5BtHQfJZuZBvFXBnIajP2EL8MOayeOJh5iu0hUFpCX7ZmBtDGKVaT 1L5Q== 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=YdGb1ZNiyhoKEy4kbd8sOl95sJgPNMgbDxCeENyhTdA=; b=Yij/Go3iMKyVrmB/0KkXAVP/F95+t20ce2Ca8UAQwAv8GowDecQHE4YroApOMha7p1 Yyrl5B4efy74LlI5Hj3FW5EP8u1RxEQrgAQLo5hTZU/ef9TnJL2C1duQKrRXO2helyKC 9xwMpoU3aAySJlBPO+NG2ZAdBlZWIfW0dk/u7wXAlloKJ1CS6O177XN6IXC89Dei58vS cwwDfZPZI39bmxaeAWjX/2qexfSqi7mhGEKQ43w4D2dye7hn5G3jL6FxDNENAwy6Lz0m uKAuRvHESDKu8h9gJi5r737q96LqrGZrXg+uDIbs1Tt0fc2kqfBr1fC+NknRb4zHyqe/ hZLg== X-Gm-Message-State: ALQs6tAKYDVduAhSvCYWI7+2qFdw6A6ZBEdshp0yY0Whk/S6JQlMtP6S yA45+WTZ0jQZg0z6GXDESzlw3su7 X-Google-Smtp-Source: AB8JxZqUAo+dzjXCqV2Mp11m+OvDy5PbqHofJpdEKyXt2rzOYrr2C8zbm2Nc73gIL+pxCAws+CXljg== X-Received: by 2002:a25:31c1:: with SMTP id x184-v6mr1629946ybx.257.1524847097483; Fri, 27 Apr 2018 09:38:17 -0700 (PDT) Received: from [192.168.1.151] ([178.54.41.83]) by smtp.gmail.com with ESMTPSA id y127-v6sm689557ywc.71.2018.04.27.09.38.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Apr 2018 09:38:16 -0700 (PDT) Subject: Re: Long running INSERT+SELECT query To: pgsql-general@lists.postgresql.org References: <11ea9b74-243d-b275-be10-1004f51a4aa6@gmail.com> <39121e73-b04a-77c4-cb5f-55530e82f0d3@aklaver.com> <320a63d9-71b5-90d1-fd2c-9ed408ae1016@aklaver.com> <5893718d-4449-741f-671a-aea1ee654944@gmail.com> <20180427093027.6959987e@wrkhors.com> From: Vitaliy Garnashevich Message-ID: <7808002c-089c-4556-52c7-0338fb864a51@gmail.com> Date: Fri, 27 Apr 2018 19:38:15 +0300 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180427093027.6959987e@wrkhors.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Everybody thanks for the suggestions! We're going to try using "SELECT 1 FROM table FOR KEY SHARE" for each of the tables, which are referenced by results, before running the big query. That should be up to a million of rows in total. It will probably not cover the case when a record is INSERT'ed and then DELETE'd after the calculation has begun, but such cases should be even more rare than the DELETE's we're currently facing. If this will not help, we'll also try to use triggers, as mentioned here: https://stackoverflow.com/a/39828119 Regards, Vitaliy