Re: [PERFORM] Long Running Update - My Solution

2011-06-28 Thread Harry Mantheakis
Hello Kevin > If you use EXPLAIN with both statements... Yes, the plans are indeed very different. Here is the statement, set to update up to 100,000 records, which took about 5 seconds to complete: UPDATE table_A SET field_1 = table_B.field_1 , field_2 = table_B.field_2 FROM table_B

Re: [PERFORM] Long Running Update - My Solution

2011-06-27 Thread Greg Smith
Harry Mantheakis wrote: The mystery remains, for me: why updating 100,000 records could complete in as quickly as 5 seconds, whereas an attempt to update a million records was still running after 25 minutes before we killed it? The way you were doing this originally, it was joining every recor

Re: [PERFORM] Long Running Update - My Solution

2011-06-27 Thread Robert Klemme
On Mon, Jun 27, 2011 at 5:37 PM, wrote: >> The mystery remains, for me: why updating 100,000 records could complete >> in as quickly as 5 seconds, whereas an attempt to update a million >> records was still running after 25 minutes before we killed it? > > Hi, there's a lot of possible causes. Us

Re: [PERFORM] Long Running Update - My Solution

2011-06-27 Thread tv
> The mystery remains, for me: why updating 100,000 records could complete > in as quickly as 5 seconds, whereas an attempt to update a million > records was still running after 25 minutes before we killed it? Hi, there's a lot of possible causes. Usually this is caused by a plan change - imagine

Re: [PERFORM] Long Running Update - My Solution

2011-06-27 Thread Kevin Grittner
Harry Mantheakis wrote: > I am glad to report that the 'salami-slice' approach worked nicely > - all done in about 2.5 hours. Glad to hear it! > The mystery remains, for me: why updating 100,000 records could > complete in as quickly as 5 seconds, whereas an attempt to update > a million rec

Re: [PERFORM] Long Running Update - My Solution

2011-06-27 Thread Harry Mantheakis
I am glad to report that the 'salami-slice' approach worked nicely - all done in about 2.5 hours. Instead of using an all-in-one-go statement, we executed 800 statements, each updating 100,000 records. On average it tool about 10-seconds for each statement to return. This is "thinking out of

Re: [PERFORM] Long Running Update

2011-06-24 Thread Harry Mantheakis
I called VACUUM on the database after abandoning the original all-in-one update. And I have a daily cron script that executes the following statement: sudo -u postgres /usr/bin/vacuumdb -U postgres --all --analyze But I had not considered using CLUSTER - I will certainly look into that. Thank

Re: [PERFORM] Long Running Update

2011-06-24 Thread Kevin Grittner
Harry Mantheakis wrote: > I have stopped the all-in-one-go update from executing, and now I > am executing a series of statements, each constrained to update no > more than 100,000 records at a time. > > Interesting fact: updating 100,000 rows takes 5 seconds. Quick. One last thing -- all the

Re: [PERFORM] Long Running Update

2011-06-24 Thread Harry Mantheakis
> try a series of smaller examples... Mark, that was the tip the saved me! Many thanks. Harry Mantheakis London, UK -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance

Re: [PERFORM] Long Running Update

2011-06-24 Thread Harry Mantheakis
Thank you so much for all the feedback, Kevin - much appreciated. I have stopped the all-in-one-go update from executing, and now I am executing a series of statements, each constrained to update no more than 100,000 records at a time. Interesting fact: updating 100,000 rows takes 5 seconds.

Re: [PERFORM] Long Running Update

2011-06-24 Thread Kevin Grittner
Harry Mantheakis wrote: >> It will be a lot faster if you can drop all indices... > > This is counter-intuitive - because the WHERE clause is matching > the only two indexed fields, and my understanding is that querying > on indexed fields is faster than querying on fields that are not > indexe

Re: [PERFORM] Long Running Update

2011-06-24 Thread Kevin Grittner
Harry Mantheakis wrote: > IOW how do I convert - guesstimate! - these numbers into > (plausible) time values? They are abstract and it only matters that they are in the right ratios to one another so that the planner can accurately pick the cheapest plan. With the default settings, seq_page_c

Re: [PERFORM] Long Running Update

2011-06-24 Thread Kevin Grittner
Mark Thornton wrote: > On 23/06/11 16:05, Harry Mantheakis wrote: >> UPDATE >> table_A >> [ ... ] >> FROM >> table_B >> WHERE >> table_B.id = table_A.id > I frequently get updates involving a FROM clause wrong --- the > resulting table is correct but the running time is quadratic. The most

Re: [PERFORM] Long Running Update

2011-06-24 Thread Mark Thornton
On 23/06/11 16:05, Harry Mantheakis wrote: Hello I am attempting to run an update statement that copies two fields from one table to another: UPDATE table_A SET ( field_1 , field_2 ) = ( table_B.field_1 , table_B.field_2 ) FROM table_B WHERE table_B.id = table_A.id ; I frequently get

Re: [PERFORM] Long Running Update

2011-06-24 Thread Harry Mantheakis
Thanks again Claudio. It does not look like its locked/blocked - but your hint about doing this task in smaller batches is a good one, and it would be easy enough to organise. I am going to let this task run over the week-end, and then decide. Either way, I shall update this thread. Much o

Re: [PERFORM] Long Running Update

2011-06-24 Thread Vitalii Tymchyshyn
24.06.11 14:16, Harry Mantheakis написав(ла): > EXPLAIN the statement Here is the EXPLAIN result: -- QUERY PLAN -- Hash Join (cost=2589312.08..16596998.47 row

Re: [PERFORM] Long Running Update

2011-06-24 Thread Claudio Freire
On Fri, Jun 24, 2011 at 1:19 PM, Harry Mantheakis wrote: > >> there are lots of ways in which it could be struggling... > > I have been monitoring the server with IOSTAT -d and IOSTAT -c and I cannot > see anything alarming. If iostat doesn't show disk load, either iostat doesn't work well (which

Re: [PERFORM] Long Running Update

2011-06-24 Thread Harry Mantheakis
Thank you Claudio. > there are lots of ways in which it could be struggling... I have been monitoring the server with IOSTAT -d and IOSTAT -c and I cannot see anything alarming. > It will be a lot faster if you can drop all indices... This is counter-intuitive - because the WHERE clause is m

Re: [PERFORM] Long Running Update

2011-06-24 Thread Harry Mantheakis
Thank you Kevin. > SET field_1 = table_B.field_1, field_2 = table_B.field_2 I will try that, if I have to next time. > add something like this toyour WHERE clause, > to prevent unnecessary updates: > > AND (table_B.field_1 IS DISTINCT FROM table_A.field_1 >OR table_B.field_2 IS DISTINCT F

Re: [PERFORM] Long Running Update

2011-06-23 Thread Kevin Grittner
Harry Mantheakis wrote: > UPDATE >table_A > SET > ( >field_1 > , field_2 > ) = ( > table_B.field_1 > , table_B.field_2 > ) > FROM > table_B > WHERE > table_B.id = table_A.id > ; I would have just done: SET field_1 = table_B.field_1, field_2 = table_B.field_2 instead of using row v

Re: [PERFORM] Long Running Update

2011-06-23 Thread Claudio Freire
On Thu, Jun 23, 2011 at 5:05 PM, Harry Mantheakis wrote: > TOP, FREE and VMSTAT utilities indicate that only about half of the 6GB of > memory is being used, so I have no reason to believe that the server is > struggling. You have a hinky idea of server load. Mind you, there are lots of ways in

[PERFORM] Long Running Update

2011-06-23 Thread Harry Mantheakis
Hello I am attempting to run an update statement that copies two fields from one table to another: UPDATE table_A SET ( field_1 , field_2 ) = ( table_B.field_1 , table_B.field_2 ) FROM table_B WHERE table_B.id = table_A.id ; Table "table_B" contains almost 75 million records, with IDs t