Re: Long running INSERT+SELECT query - Mailing list pgsql-general

From Alvaro Herrera
Subject Re: Long running INSERT+SELECT query
Date
Msg-id 20180426210458.phfgeaxsrl2f6zhk@alvherre.pgsql
Whole thread Raw
In response to Re: Long running INSERT+SELECT query  (Vitaliy Garnashevich <vgarnashevich@gmail.com>)
List 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


pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: Long running INSERT+SELECT query
Next
From: Adrian Klaver
Date:
Subject: Re: PGAdmin4 debugger - unable to call ltree functions