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 1gkZOF-00073g-1L for pgsql-general@arkaria.postgresql.org; Fri, 18 Jan 2019 19:01:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gkZOC-00035i-2X for pgsql-general@arkaria.postgresql.org; Fri, 18 Jan 2019 19:01:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gkZOB-00035b-R0 for pgsql-general@lists.postgresql.org; Fri, 18 Jan 2019 19:01:11 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gkZO8-0000Up-Pd for pgsql-general@postgresql.org; Fri, 18 Jan 2019 19:01:11 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x0IJ10um001131; Fri, 18 Jan 2019 14:01:00 -0500 From: Tom Lane To: Adrian Klaver cc: George Woodring , pgsql-general Subject: Re: Why adding BEFORE TRIGGER affect client CPU? In-reply-to: <6e15d38d-e6f9-1836-15db-5b4e5e9f3a94@aklaver.com> References: <6e15d38d-e6f9-1836-15db-5b4e5e9f3a94@aklaver.com> Comments: In-reply-to Adrian Klaver message dated "Fri, 18 Jan 2019 10:28:21 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1129.1547838060.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Fri, 18 Jan 2019 14:01:00 -0500 Message-ID: <1130.1547838060@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Adrian Klaver writes: > On 1/18/19 10:23 AM, George Woodring wrote: >> We recently changed the process to do a BEFORE TRIGGER to do the >> calculation between OLD and NEW instead of the separate function with >> the SELECT. > So what was the exact change? >> After doing this, CPU on our two client servers went crazy.  CPU on the >> database servers look unchanged.  Rolling back this change fixed our >> client CPU issue. > What is the client server and what is it doing? Indeed. There's no direct way that messing with a trigger would have caused extra CPU on the client side. I speculate that the trigger caused the data to look different in a way that your client app wasn't expecting, causing it to do something funny --- maybe loop trying to find a matching record, or something like that. Or maybe removing the step that did the calculation client-side had side effects you weren't expecting --- what uses that value client-side, exactly? regards, tom lane