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 1fCBUI-0004Vw-Nb for pgsql-general@arkaria.postgresql.org; Fri, 27 Apr 2018 22:05:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fCBUG-0007sn-Ut for pgsql-general@arkaria.postgresql.org; Fri, 27 Apr 2018 22:05:04 +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 1fCBUG-0007sX-Mf for pgsql-general@lists.postgresql.org; Fri, 27 Apr 2018 22:05:04 +0000 Received: from mail-pg0-x22e.google.com ([2607:f8b0:400e:c05::22e]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fCBU9-0000jg-0X for pgsql-general@lists.postgresql.org; Fri, 27 Apr 2018 22:05:03 +0000 Received: by mail-pg0-x22e.google.com with SMTP id e12-v6so2471293pgn.9 for ; Fri, 27 Apr 2018 15:04:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=VNDqxeP+mWcktMpKzkoZsNVsTgVuF0WZXpI3to01ky8=; b=JfqMJbnsjkzPUzXAUIvDStIsrtC9tKWIzCmzTYs8Td04WRXIAobfVBDYKV9miOWsU4 zU4kBfaGm/n4O628F5wA2Mhyb8FYQfr+Vo1St+7QNAHdd2U/kX5IXaiMMGs8f6cATb0u /xmj6sURL/M54JcBX/xIn/6yvcKO1TCVz95gvr5eb84M9YSwGFWkWuq/Jh50WmUlMgGe wskuOXrPieOgEFgQPxpbuwqXpxFGJzmFiSnMQ8q7n26HB96UEkbHEtVBT/HpatS/5yW1 VRqIRk9oKuhdIplLrA9ToSEv26MuDO4LV2WVZH9AmUQobRxTLtji4j7cGlHPKYtyQVXc jRxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=VNDqxeP+mWcktMpKzkoZsNVsTgVuF0WZXpI3to01ky8=; b=fCnmp/mnXjdWyA9Kg4pUzPOdZi+h2HDx+Z77i3VXTEMsBbnAJBw4eRDIUbGJ6l6DoA yff4JKIBSJzL7v0ZyW/4BnktMdisEoHaQEKSrurQg0WtI/C/L5J9KZcK564YId4MJdOZ Bq8fuOEbYERU62JZA+sgZvVIHaveilwsZS5kIGP4VsjHZY56M5VkDl1gecOHi/1RF7Kp hDE/363u9ncGuixUBIJBSf/H4JS+cZ3BtrVsdsrKdkxJTccqLkOTsqTKDwN+QKq9RTQ5 U9IgLJp0ub9jbRlPpmT38iHNimX4ccWI6SpH0dqdnWh7s8zR/YWJn24SL4dhhrv5JMl6 1f1w== X-Gm-Message-State: ALQs6tCbEmepv6EXpVqfxnBNvi6jqgJAGzjapw9rXCxLxH65fU/C3X2Z cKg9UFEYV74GHWq4RwgeYZY4keTH X-Google-Smtp-Source: AB8JxZoAOhL7v5dJeD8nDKX/V9TIIP3EVAy5Wl8j2aD/j7Y545DTsx2QeZkGEck0iF58VIaPvCXc3w== X-Received: by 2002:a17:902:9a9:: with SMTP id 38-v6mr3849453pln.114.1524866694645; Fri, 27 Apr 2018 15:04:54 -0700 (PDT) Received: from tim-desktop (2001-44b8-31f2-bb00-982f-cbf1-fdfd-ac26.static.ipv6.internode.on.net. [2001:44b8:31f2:bb00:982f:cbf1:fdfd:ac26]) by smtp.gmail.com with ESMTPSA id h9-v6sm3604956pgs.29.2018.04.27.15.04.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 27 Apr 2018 15:04:53 -0700 (PDT) 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> <7808002c-089c-4556-52c7-0338fb864a51@gmail.com> <20180427145041.031abeda.lembark@wrkhors.com> User-agent: mu4e 0.9.18; emacs 26.1 From: Tim Cross To: Steven Lembark Cc: pgsql-general@lists.postgresql.org Subject: Re: Long running INSERT+SELECT query In-reply-to: <20180427145041.031abeda.lembark@wrkhors.com> Date: Sat, 28 Apr 2018 08:04:49 +1000 Message-ID: <87lgd8cnlq.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Steven Lembark writes: > On Fri, 27 Apr 2018 19:38:15 +0300 > Vitaliy Garnashevich wrote: > >> 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. > > Thing about using a couple of Materialized Views for the worst > part of it. +1 re: materialised views - I have found them to be extremely useful for situations where you want a snapshot of data and need to present it in a way which is easier to process, especially when the underlying data is changing faster than your reporting process can generate the report. -- Tim Cross