Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iob1Y-00066Q-8p for pgsql-general@arkaria.postgresql.org; Mon, 06 Jan 2020 22:39:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iob1X-00050O-3F for pgsql-general@arkaria.postgresql.org; Mon, 06 Jan 2020 22:38:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iob1W-0004zQ-DA for pgsql-general@lists.postgresql.org; Mon, 06 Jan 2020 22:38:58 +0000 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iob1S-0002A2-VH for pgsql-general@lists.postgresql.org; Mon, 06 Jan 2020 22:38:57 +0000 Received: by mail-pg1-x52b.google.com with SMTP id b137so27511335pga.6 for ; Mon, 06 Jan 2020 14:38:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alaska-edu.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=2vxTr3tbNAKSYpl42jPQV0kShXmYKqQn8pxQJ4wn0ZQ=; b=jqE4VLllzk+MWez5jHqN5V3mBFWKoTIDGkRyFLx3EPYjp2qLIV2AtQ/blA1Yz+7+10 bjiJjT+tpH9IimM9iguPagdefAEjM6HXYBekST0OC3JXuCDE2JlriDhw53T1t+cKYbOz yw+bs5EMMO6K4kthPqoMJx1j0y6YpwevvQY9N1WCHaoqw94O78/I/uD2KExujT4JPkML OAWrLlYi8kYPOm3jNlewXm7GotQD2EQ9IZMU19YoPTqqxWlNo9Dv8y9MoJaHJBZY4D9o chx5OqlkIs2hdoLxtY1Y4WaXZHcpNVWmNLiQuqRiqwZd8o9HXWiU/LGtGmwSute0P8AG aPBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=2vxTr3tbNAKSYpl42jPQV0kShXmYKqQn8pxQJ4wn0ZQ=; b=hF/qNotfEOMHPo+JwVikif4U3MGgjRt2yidBrXMsVBGZ+CqWtBKtYxeCyYl9I+EbHv VpRbDe1+N0qeSwmWEBqmDl+EuLJ7BHau6Zvx2M2iqeHiyH895rcnw/sqVd9/bt2wfOUT 3Foxyn6XZ5jHTVYQYjgKvSbwnDI9XiKx1AB3yJBt1Ks4dKWd9cKQT2im3L+ZZW5fxc5L zHY/+FPusoXXbJEPmuLkmCrcXHzrW3C7i9ekYGJHAD6AY8wXMkmqMQjmjsDisg+Rc+FH AR794y+ZbIga0SxZvzryBaaRd1I8SSs7hNvG38Nv0MBswiXATR7WM10nu4lYnuNCinXA Iglw== X-Gm-Message-State: APjAAAWu6ZNgvr/IJa49KBV7yI2Q5EbBx9YIlZFrlrrsRK5jYoVI6iYD zkVyucvlorvuinB2WpQHmcrTWA== X-Google-Smtp-Source: APXvYqz97IPMbZVmFf72W4y+FwkEQymKe4rRE0M+eKaO8hstsv7a4VWnSUzSiisg1dRghjS+D8795A== X-Received: by 2002:a62:be12:: with SMTP id l18mr93272105pff.226.1578350333667; Mon, 06 Jan 2020 14:38:53 -0800 (PST) Received: from tokuuke.giseis.alaska.edu ([137.229.32.97]) by smtp.gmail.com with ESMTPSA id i11sm26539048pjg.0.2020.01.06.14.38.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jan 2020 14:38:52 -0800 (PST) From: Israel Brewster Message-Id: <57C76375-D3CC-4FF5-A214-C45BC9DF996E@alaska.edu> Content-Type: multipart/alternative; boundary="Apple-Mail=_4D173A04-3FC3-41F1-BD1F-BE526C692E7C" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: UPDATE many records Date: Mon, 6 Jan 2020 13:38:51 -0900 In-Reply-To: Cc: Michael Lewis , Rob Sargent , Alban Hertroys , Christopher Browne , "pgsql-generallists.postgresql.org" To: Justin References: <97518FCA-F286-4A6A-803F-46A109196C71@alaska.edu> <8AB099DA-99B4-421A-BD15-638A367EE722@alaska.edu> <91870B50-CDFB-489C-BE01-59B281A9CDCD@gmail.com> <9BB7DDC4-16D7-4137-8F6A-5C4F4F7AB2A0@gmail.com> <2A41E4CD-6C38-46F3-A9C7-695EBC0DBA0F@alaska.edu> <1E69AD3D-76C5-4300-AB5B-E75CE9E1E9DE@alaska.edu> X-Mailer: Apple Mail (2.3445.104.11) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_4D173A04-3FC3-41F1-BD1F-BE526C692E7C Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jan 6, 2020, at 12:49 PM, Justin wrote: >=20 > What was the HD wait time ? What tool is being use to monitor the = server resources?? No idea on the HD wait time - how would I best monitor that? That said, = this machine does have NVMe drives, so the speed should be fairly = high/wait time fairly low. It=E2=80=99s also running as a VM, which = could affect things, but is a bit of a moot point as far as this update = goes. As far as monitoring server resources, I was just using top. > It appears based on this information there is allot more going on than = a simple Update command Depending on your definition of =E2=80=9Csimple update=E2=80=9D of = course, very true. As I stated in the original message, the actual = update value is the result of a function. The psql command is a simple = update, but the function does a bit of stuff (primarily trigonometry). = According to the EXPLAIN ANALYZE, about .7 ms of stuff per record, which = of course is most of the runtime. It is entirely possible that the = function could be optimized to run more quickly. >=20 > Moving code out of the trigger probably not going to improve = performance, unless there is allot of code that does not need to be = processed for this update or code touching other tables One SELECT query on another table to get some values I need to use for = the calculation. No code that is not needed for the update. Given the = nature of this bulk update, I *could* make a separate function that = simply takes those values as parameters, since the same value will be = applied to a lot of records. I=E2=80=99d just have to be careful about = how I applied the update, so rows get processed with the correct values. = I=E2=80=99m not convinced it would be worth it though - might shave a = few hours off the total execution time (assuming that SELECT is = expensive - EXPLAIN ANLYZE shows an index scan, on a table with only = 12,761 rows, which seems to be about as simple as it gets), but I doubt = it would be enough for me to feel comfortable simply running the update = as one monolithic unit. > Study the trigger identify what has to run, pull that code out, then = disable the trigger. Move the necessary code to a new function for = Updating..=20 Sure. But I feel we are getting a bit off track. Optimizing the runtime = of the update is great, but this is a one-off (hopefully) event. I want = to accomplish it as quickly as possible, of course, but at the same time = it doesn=E2=80=99t make sense to spend a lot of time optimizing every = component of the query. The main purpose of the question was honestly = for my sanity, to reduce the likelihood of having it run for several = hours only to error out due to bad data or whatever and have to start = over from the top. Running in parallel simply seemed to be a no-brainer = option to make it go quicker, assuming CPU bound updating. Optimizations = that are going to take work are probably not worth it. We can wait for = the data to be updated. Thanks again! --- Israel Brewster Software Engineer Alaska Volcano Observatory=20 Geophysical Institute - UAF=20 2156 Koyukuk Drive=20 Fairbanks AK 99775-7320 Work: 907-474-5172 cell: 907-328-9145 >=20 > On Mon, Jan 6, 2020 at 4:24 PM Israel Brewster > wrote: >=20 >> On Jan 6, 2020, at 11:54 AM, Michael Lewis > wrote: >>=20 >> I=E2=80=99m thinking it might be worth it to do a =E2=80=9Cquick=E2=80=9D= test on 1,000 or so records (or whatever number can run in a minute or = so), watching the processor utilization as it runs. That should give me = a better feel for where the bottlenecks may be, and how long the entire = update process would take. I=E2=80=99m assuming, of course, that the = total time would scale more or less linearly with the number of records. >>=20 >> I think that depends on how your identify and limit the update to = those 1000 records. If it is using a primary key with specific keys in = an array, probably close to linear increase because the where clause = isn't impactful to the overall execution time. If you write a sub-query = that is slow, then you would need to exclude that from the time. You can = always run explain analyze on the update and rollback rather than = commit. > So a test run on 9,299 records took about 7 seconds to complete = (EXPLAIN ANALYZE output at https://explain.depesz.com/s/lIYn = if it matters), during which time I = did see a postmaster process consuming 100% CPU. Upping the test to = 20,819 records took about 16.5 seconds, so that looks relatively linear = to me. Also, CPU bound. So by my calculations, doing all 50M records = would take around 10 hours. >=20 > One potentially significant note: most of the execution time is spent = in a trigger. This trigger is actually what=E2=80=99s doing the REAL = update that I need to happen. If it would make a difference, I could = easily pull the trigger code out to a separate function that I just call = directly (with triggers temporarily disabled). My thinking is that = calling a function is calling a function, and the fact that it is = currently called via a trigger rather than direct is of little = consequence, but I=E2=80=99m willing to be corrected on that :-) >=20 > --- > Israel Brewster > Software Engineer > Alaska Volcano Observatory=20 > Geophysical Institute - UAF=20 > 2156 Koyukuk Drive=20 > Fairbanks AK 99775-7320 > Work: 907-474-5172 > cell: 907-328-9145 >=20 --Apple-Mail=_4D173A04-3FC3-41F1-BD1F-BE526C692E7C Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
On = Jan 6, 2020, at 12:49 PM, Justin <zzzzz.graf@gmail.com> wrote:

What was the HD wait time ?  What tool = is being use to monitor the server resources??

No = idea on the HD wait time - how would I best monitor that? That said, = this machine does have NVMe drives, so the speed should be fairly = high/wait time fairly low. It=E2=80=99s also running as a VM, which = could affect things, but is a bit of a moot point as far as this update = goes. As far as monitoring server resources, I was just using = top.

It appears based = on this information there is allot more going on than a simple Update = command

Depending on your definition of =E2=80=9Csimple = update=E2=80=9D of course, very true. As I stated in the original = message, the actual update value is the result of a function. The psql = command is a simple update, but the function does a bit of stuff = (primarily trigonometry). According to the EXPLAIN ANALYZE, about .7 ms = of stuff per record, which of course is most of the runtime. It is = entirely possible that the function could be optimized to run more = quickly.


Moving code out of the trigger  = probably not  going to improve performance, unless there is allot = of code  that does not need to be processed for this update or code = touching other tables

One SELECT query on another table to get some = values I need to use for the calculation. No code that is not needed for = the update. Given the nature of this bulk update, I *could* make a = separate function that simply takes those values as parameters, since = the same value will be applied to a lot of records. I=E2=80=99d just = have to be careful about how I applied the update, so rows get processed = with the correct values. I=E2=80=99m not convinced it would be worth it = though - might shave a few hours off the total execution time (assuming = that SELECT is expensive - EXPLAIN ANLYZE shows an index scan, on a = table with only 12,761 rows, which seems to be about as simple as it = gets), but I doubt it would be enough for me to feel comfortable simply = running the update as one monolithic unit.

Study the trigger identify what has to run, pull that code = out, then disable the trigger.    Move the necessary code to a = new function for Updating.. 

Sure. But I feel we are getting a bit off track. = Optimizing the runtime of the update is great, but this is a one-off = (hopefully) event. I want to accomplish it as quickly as possible, of = course, but at the same time it doesn=E2=80=99t make sense to spend a = lot of time optimizing every component of the query. The main purpose of = the question was honestly for my sanity, to reduce the likelihood of = having it run for several hours only to error out due to bad data or = whatever and have to start over from the top. Running in parallel simply = seemed to be a no-brainer option to make it go quicker, assuming CPU = bound updating. Optimizations that are going to take work are probably = not worth it. We can wait for the data to be updated.

Thanks again!

---
Israel Brewster
Software Engineer
Alaska Volcano = Observatory 
Geophysical Institute - UAF 
2156 Koyukuk Drive 
Fairbanks AK = 99775-7320
Work: 907-474-5172
cell: =  907-328-9145



On Mon, Jan 6, 2020 at 4:24 PM Israel = Brewster <ijbrewster@alaska.edu> wrote:

On Jan 6, 2020, at 11:54 AM, = Michael Lewis <mlewis@entrata.com> wrote:

I=E2=80=99m thinking it might be worth it to do a =E2=80=9Cquic= k=E2=80=9D test on 1,000 or so records (or whatever number can run in a = minute or so), watching the processor utilization as it runs. That = should give me a better feel for where the bottlenecks may be, and how = long the entire update process would take. I=E2=80=99m assuming, of = course, that the total time would scale more or less linearly with the = number of records.

I think that depends on how your = identify and limit the update to those 1000 records. If it is using a = primary key with specific keys in an array, probably close to = linear increase because the where clause isn't impactful to the = overall execution time. If you write a sub-query that is slow, then you = would need to exclude that from the time. You can always run explain = analyze on the update and rollback rather than commit.
So a test run on 9,299 records took about 7 = seconds to complete (EXPLAIN ANALYZE output at https://explain.depesz.com/s/lIYn if it matters), = during which time I did see a postmaster process consuming 100% CPU. = Upping the test to 20,819 records took about 16.5 seconds, so that looks = relatively linear to me. Also, CPU bound. So by my calculations, doing = all 50M records would take around 10 hours.

One potentially significant note: most = of the execution time is spent in a trigger. This trigger is actually = what=E2=80=99s doing the REAL update that I need to happen. If it would = make a difference, I could easily pull the trigger code out to a = separate function that I just call directly (with triggers temporarily = disabled). My thinking is that calling a function is calling a function, = and the fact that it is currently called via a trigger rather than = direct is of little consequence, but I=E2=80=99m willing to be corrected = on that :-)

---
Israel Brewster
Software Engineer
Alaska Volcano = Observatory 
Geophysical Institute - UAF 
2156 Koyukuk Drive 
Fairbanks AK = 99775-7320
Work: 907-474-5172
cell: =  907-328-9145


= --Apple-Mail=_4D173A04-3FC3-41F1-BD1F-BE526C692E7C--