Re: Long running INSERT+SELECT query

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Vitaliy Garnashevich <vgarnashevich(at)gmail(dot)com>
Cc: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Long running INSERT+SELECT query
Date: 2018-04-26 21:04:58
Message-ID: 20180426210458.phfgeaxsrl2f6zhk@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2018-04-26 21:23:01 Re: PGAdmin4 debugger - unable to call ltree functions
Previous Message David G. Johnston 2018-04-26 20:40:16 Re: Long running INSERT+SELECT query