Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jRKlj-00068N-Kh for pgsql-general@arkaria.postgresql.org; Wed, 22 Apr 2020 19:10:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jRKli-0004fa-CS for pgsql-general@arkaria.postgresql.org; Wed, 22 Apr 2020 19:10:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jRKlh-0004fT-U4 for pgsql-general@lists.postgresql.org; Wed, 22 Apr 2020 19:10:46 +0000 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jRKlf-0002aI-LP for pgsql-general@lists.postgresql.org; Wed, 22 Apr 2020 19:10:44 +0000 Received: by mail-oi1-x22b.google.com with SMTP id q204so2821305oia.13 for ; Wed, 22 Apr 2020 12:10:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=85K0VOjCufVPfEpTkXK+39/o1ozR1hX/mDMGS+4eFng=; b=X9LTQ4n3xXwkowkucrIIPGDkiEXyjAnFGBS+6XQKC9/LIxFBdI5mEaYUchh1wqAxgB SwaiVeJ9rcnaJVEUupPzooFCUZgkQAo3x4TIy2RbtR6+HsD2rSG0j3SYGgY6HvFAd59F 4g4VgtBcD6mGuQj+MpcO0L4rwCLxOYcKIzJ2TOYXk1wRJIMi/6M/8QE0sSwETZWB2/Md AhyKCi0RWT5FK0h0HyMWEL1b9rdxX5oiA/r180e9LRfjRU1nQ9JYPRPTJ7AletTcEC8/ FcyR8FLPofZ846L3kY+ClmLi6LwqeMYLVVje0kmrjEdBpclkm8nBaRKI2HQlqoqTjPJc Zo3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=85K0VOjCufVPfEpTkXK+39/o1ozR1hX/mDMGS+4eFng=; b=fwcOYGbkqK65ia5FKR/kpEC0RMulRRU2yP4V5KMK1Nh75mEzO/713bhDhzoiYUAawh jU4sIL8g93BNrdy2Pxl6VaOgeoPQolSVRe7CHDDoTAY1fbNFjrcK0mn1FjUrBB3OjMYF XmebeID+DjSF/aZbOEzTk3mYRziEolMiIt+S3ifVZ3uu9rgfTwTNbx1hqqw+BO8bHlUO XvXjbaFUxb/t9hYwK499pR9j3JFf+nXtIcFDcr4fETXuOq8nyguT3NW6gDuRetAtRK9P ga6ZPkQIYK0xobu5/5QjtVt7ICEVeVG9X8IzeEVYBtZeeN0Vz7U7nabZnIxtS11Xq/VR uCJA== X-Gm-Message-State: AGi0PuZ1wluSLTPV6F1H3gIiTTYPvxo1G0DLhMuMGXUWyNpHQW+L3h0P BVaaiZ3Y4tgv3dvT+6YK/pT99qtQvgY= X-Google-Smtp-Source: APiQypISCySzbLw3nChKsbL6pDzT58f+eH2S8i0Sxmjqc5h7FX5+Zn8Rssu76MBgemWjstNfUmJGYw== X-Received: by 2002:a54:4199:: with SMTP id 25mr383433oiy.136.1587582642647; Wed, 22 Apr 2020 12:10:42 -0700 (PDT) Received: from [192.168.1.10] (ip70-186-126-197.no.no.cox.net. [70.186.126.197]) by smtp.googlemail.com with ESMTPSA id r132sm24635oif.26.2020.04.22.12.10.41 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Apr 2020 12:10:41 -0700 (PDT) Subject: Re: how to slow down parts of Pg To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: <973e21ee-f1f7-6eee-c804-404884302f49@gmail.com> Date: Wed, 22 Apr 2020 14:10:41 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------7D75727B2E28E7E24CE3A8E7" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------7D75727B2E28E7E24CE3A8E7 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit What you need is async replication instead of synchronous replication. On 4/21/20 3:30 PM, Kevin Brannen wrote: > > I have an unusual need:  I need Pg to slow down. I know, we all want our > DB to go faster, but in this case it's speed is working against me in 1 area. > > We have systems that are geo-redundant for HA, with the redundancy being > handled by DRBD to keep the disks in sync, which it does at the block > level. For normal operations, it actually works out fairly well. That > said, we recognize that what we really need to do is one of the forms of > streaming (ch 26 of the manual) which I believe would help this problem a > lot if not solve it -- but we don't have the time to do that at the > moment. I plan and hope to get there by the end of the year. The part that > hurts so bad is when we do maintenance operations that are DB heavy, like > deleting really old records out of archives (weekly), moving older records > from current tables to archive tables plus an analyze (every night), > running pg_backup (every night), other archiving (weekly), and vacuum full > to remove bloat (once a quarter). All of this generates a lot of disk > writes, to state the obvious. > > The local server can handle it all just fine, but the network can't handle > it as it tries to sync to the other server. Sometimes we can add network > bandwidth, many times we can't as it depends on others. To borrow a phrase > from the current times, we need to flatten the curve. 😊 > > A few parts of our maintenance process I've tamed by doing "nice -20" on > the process (e.g. log rotation); but I can't really do that for Pg because > the work gets handed off to a background process that's not a direct child > process … and I don't want to slow the DB as a whole because other work is > going on (like handling incoming data). > > Part of the process I've slowed down by doing the work in chunks of 10K > rows at a time with a pause between each chunk to allow the network to > catch up (instead of an entire table in 1 statement). This sort of works, > but some work/SQL is between hard to next-to-impossible to break up like > that. That also produces some hard spikes, but that's better than the > alternative (next sentence). Still, large portions of the process are hard > to control and just punch the network to full capacity and hold it there > for far too long. > > So, do I have any other options to help slow down some of the Pg > operations? Or maybe some other short-term mitigations we can do with Pg > configurations? Or is this a case where we've already done all we can do > and the only answer is move to WAL streaming as fast as possible? > > If it matters, this is being run on Linux servers. Pg 12.2 is in final > testing and will be rolled out to production soon -- so feel free to offer > suggestions that only apply to 12.x. > > Thanks, > > Kevin > > This e-mail transmission, and any documents, files or previous e-mail > messages attached to it, may contain confidential information. If you are > not the intended recipient, or a person responsible for delivering it to > the intended recipient, you are hereby notified that any disclosure, > distribution, review, copy or use of any of the information contained in > or attached to this message is STRICTLY PROHIBITED. If you have received > this transmission in error, please immediately notify us by reply e-mail, > and destroy the original transmission and its attachments without reading > them or saving them to disk. Thank you. -- Angular momentum makes the world go 'round. --------------7D75727B2E28E7E24CE3A8E7 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit What you need is async replication instead of synchronous replication.

On 4/21/20 3:30 PM, Kevin Brannen wrote:

I have an unusual need:  I need Pg to slow down. I know, we all want our DB to go faster, but in this case it's speed is working against me in 1 area.

 

We have systems that are geo-redundant for HA, with the redundancy being handled by DRBD to keep the disks in sync, which it does at the block level. For normal operations, it actually works out fairly well. That said, we recognize that what we really need to do is one of the forms of streaming (ch 26 of the manual) which I believe would help this problem a lot if not solve it -- but we don't have the time to do that at the moment. I plan and hope to get there by the end of the year. The part that hurts so bad is when we do maintenance operations that are DB heavy, like deleting really old records out of archives (weekly), moving older records from current tables to archive tables plus an analyze (every night), running pg_backup (every night), other archiving (weekly), and vacuum full to remove bloat (once a quarter). All of this generates a lot of disk writes, to state the obvious.

 

The local server can handle it all just fine, but the network can't handle it as it tries to sync to the other server. Sometimes we can add network bandwidth, many times we can't as it depends on others. To borrow a phrase from the current times, we need to flatten the curve. 😊

 

A few parts of our maintenance process I've tamed by doing "nice -20" on the process (e.g. log rotation); but I can't really do that for Pg because the work gets handed off to a background process that's not a direct child process … and I don't want to slow the DB as a whole because other work is going on (like handling incoming data).

 

Part of the process I've slowed down by doing the work in chunks of 10K rows at a time with a pause between each chunk to allow the network to catch up (instead of an entire table in 1 statement). This sort of works, but some work/SQL is between hard to next-to-impossible to break up like that. That also produces some hard spikes, but that's better than the alternative (next sentence). Still, large portions of the process are hard to control and just punch the network to full capacity and hold it there for far too long.

 

So, do I have any other options to help slow down some of the Pg operations? Or maybe some other short-term mitigations we can do with Pg configurations? Or is this a case where we've already done all we can do and the only answer is move to WAL streaming as fast as possible?

 

If it matters, this is being run on Linux servers. Pg 12.2 is in final testing and will be rolled out to production soon -- so feel free to offer suggestions that only apply to 12.x.

 

Thanks,

Kevin

This e-mail transmission, and any documents, files or previous e-mail messages attached to it, may contain confidential information. If you are not the intended recipient, or a person responsible for delivering it to the intended recipient, you are hereby notified that any disclosure, distribution, review, copy or use of any of the information contained in or attached to this message is STRICTLY PROHIBITED. If you have received this transmission in error, please immediately notify us by reply e-mail, and destroy the original transmission and its attachments without reading them or saving them to disk. Thank you.

--
Angular momentum makes the world go 'round.
--------------7D75727B2E28E7E24CE3A8E7--