pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Vitaliy Garnashevich <vgarnashevich@gmail.com>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: Postgres General <pgsql-general@postgresql.org>
Subject: Re: Long running INSERT+SELECT query
Date: Thu, 26 Apr 2018 18:04:58 -0300
Message-ID: <20180426210458.phfgeaxsrl2f6zhk@alvherre.pgsql> (raw)
In-Reply-To: <5893718d-4449-741f-671a-aea1ee654944@gmail.com>

Vitaliy Garnashevich wrote:
> 
> > Have not worked through all of the above, but a first draft suggestion:
> > 
> > Move the SELECT minus the aggregation functions into a sub-query that
> > uses FOR UPDATE. Then do the aggregation on the results of the
> > sub-query.
> 
> The aggregated table has hundreds of millions of rows, and the query runs
> for many hours (which is one of the reasons why it's better not to fail). I
> really doubt that row level locking would work. That would be a lot of RAM
> just to hold all the locks.

Row locks are not stored in memory.

Of course, a FOR KEY SHARE lock would block DELETEs that try to remove
the locked row.

I think your proposed strategy of trying to merge what other processes
did while you were copying is very problematic.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




view thread (16+ messages)  latest in thread

Message-ID: <20180426210458.phfgeaxsrl2f6zhk@alvherre.pgsql>
Permalink:  ../20180426210458.phfgeaxsrl2f6zhk@alvherre.pgsql/
Also on:    postgresql.org/message-id/20180426210458.phfgeaxsrl2f6zhk@alvherre.pgsql

 · 

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: alvherre@2ndquadrant.com, vgarnashevich@gmail.com, adrian.klaver@aklaver.com
  Subject: Re: Long running INSERT+SELECT query
  In-Reply-To: <20180426210458.phfgeaxsrl2f6zhk@alvherre.pgsql>
  References: <5893718d-4449-741f-671a-aea1ee654944@gmail.com> <20180426210458.phfgeaxsrl2f6zhk@alvherre.pgsql>

* 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