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 1gPKkK-0001rU-Nc for pgsql-general@arkaria.postgresql.org; Wed, 21 Nov 2018 05:08:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gPKkJ-0005OA-9S for pgsql-general@arkaria.postgresql.org; Wed, 21 Nov 2018 05:08:15 +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 1gPKkI-0005O3-MM for pgsql-general@lists.postgresql.org; Wed, 21 Nov 2018 05:08:15 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gPKkF-0007ju-9Z for pgsql-general@postgresql.org; Wed, 21 Nov 2018 05:08:13 +0000 Received: by mail-pl1-x643.google.com with SMTP id gn14so3683004plb.10 for ; Tue, 20 Nov 2018 21:08:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=ZdKnzzlhr7L1+JDLDbP5S7aObgpiHb0Fya5JlAzrpsk=; b=LAVHL6rJzBVPIJYHHeBGZSqfbSSmeDIGnq8q4qWhznwDq0dRnm7ZyAGB5RK9CXUyCJ kIn2jHtR+wmoNew+OfUjWfh7sFg57M6xEvGuSYAkGxjpWVLC2ZR3b3xVrDV9J3OsVw6P SuOFbVQTNCL4XCwLa7ld+wpwJg0uvLoHdnZhI314my4b3SxH4NE4CWLoX0zU879qi+Zx ps5CU8cY1SL1WAuG7kyr2L/nqGET60jnPyw4RzHZdpy4yWjVU7Xtd82bK03joL5SvFCW mIxY5q4S1NNx6Cj15eUZ93dePPAQfifCt7v4sll7HF211/bD6Aj4wbkZK31OfeyvoWTv pEoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=ZdKnzzlhr7L1+JDLDbP5S7aObgpiHb0Fya5JlAzrpsk=; b=lYq8GaqpoRjDbivSU0NgzSOm0JB2Pg7dDFl6DJL8JVVdpUAIDmnPcJ9jFwXMN8grMG Czx5/RXKByjv/5k0MzYSwvtlJHGykeR6b8OdTlbLXl9XRRGA4lcTHIOoGThf7n/tJDmi f4vRRBKxZ/qD/5vvbbeD1lmup/Svxe4OYFkJ3emKhquhNduwRywdtjcl1cdWphA88wo3 c0ApiYLYMfM8nBbJJaScxQEii1PBiCcIEezBv5yTc8XVOGviDurIUJFQzOHJsE28aeAn 7KAVttq6B6jg3p4zwU+edNFuJpU2Z2orAFrXRfDNtYSUNqt3mD15/not6p2OXKccqYaY mq1A== X-Gm-Message-State: AA+aEWYy2y4otbuuQSmdSm2tXwvzOgNuJRhohcOpGyt5p4A2tv8uZGW6 QFQBx4eXCO85MuH2881LNTPU1umO X-Google-Smtp-Source: AFSGD/UoDi2ZnK7rOrddpjBDfYjMZv/FFz6jEKpv5Ukcgj6f9+QuYrLwmitbCF/tQALes0ZGdBOyVQ== X-Received: by 2002:a63:88c7:: with SMTP id l190mr4563790pgd.110.1542776889435; Tue, 20 Nov 2018 21:08:09 -0800 (PST) Received: from ?IPv6:2601:645:4202:82b0:eab1:fcff:fe72:9683? ([2601:645:4202:82b0:eab1:fcff:fe72:9683]) by smtp.gmail.com with ESMTPSA id y11-v6sm13829982pfk.70.2018.11.20.21.08.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 21:08:08 -0800 (PST) Subject: Re: replication lag despite corrective config To: Rene Romero Benavides Cc: pgsql-general@postgresql.org References: From: Wyatt Alt Message-ID: Date: Tue, 20 Nov 2018 21:08:03 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------612CC71E0FDB302D01F0E07C" 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. --------------612CC71E0FDB302D01F0E07C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi Rene, On 11/19/18 8:46 PM, Rene Romero Benavides wrote: > Not sure about the root cause but I can make these observations and > raise some questions: > 1) 9.6.6 is five bug fix versions behind Valid point to raise. > 2) 300GB is so big a table, wouldn't make sense to you to partition it ? > 2a) or if it's partitioned, doesn't the time of creation or dropping > of new partitions match the time of the conflict? Partitioning is in the works, but none at the moment. > > 3) can you track long running transactions on the master? > 4) what are the isolation levels on master / replica? Transaction times on the master max out around two minutes. On the replica they are much longer -- numerous 1 - 2 hour transactions per day, and occasional ones as long as 10 - 20 hours. Isolation levels are read committed everywhere. > 5) check for active locks in the replica, I guess you should see some > blocked transactions during big delays, I've seen this in the past > when standby_feedback is turned off. > 6) any out of the ordinary messages in the replica's logs? any > evidence that has been canceling statements? I'll make a note to record the active locks next time. I haven't seen anything unusual in the logs during these incidents, but have observed statements getting canceled at other times, which is why I think the config mostly works. > 7) are master and replica exactly the same in terms of resources and > main parameters? > 8) how is performance in both nodes while the big delay is happening? > IO / cpu load / etc. This brings up a good detail I forgot to mention originally. During the last incident, IO utilization on the replica was near 100%, and had been for several hours, which I believe was due to the long queries I canceled.  Now that I think about it, I wonder if the lag may have arisen from IO contention between the query and WAL replay, rather than a query conflict. > > Also, check this out: > https://www.alibabacloud.com/forum/read-383 > Thanks, interesting reading. > > Am Mo., 19. Nov. 2018 um 21:46 Uhr schrieb Wyatt Alt > >: > > Sorry, I see now there was a similar question a few days ago: > https://www.postgresql.org/message-id/CAJw4d1WtzOdYzd8Nq2=uFK+Z0JY0L_pfg9TvCWPrmt3NCZq9GA@mail.gmail.com > > Two ideas proposed (aside from disconnects): > * Autovacuum is truncating a page on the master and taking an > AccessExclusiveLock on the table in use on the replica > * A "pin conflict", which I'm still unfamiliar with. > > The user's response says they are in the first bucket, but the > argument relies on max_standby_streaming_delay set to -1, while > mine is 5 minutes. I need to understand pin conflicts better, but > the likely scenario Andrew outlined doesn't apply to me. My > offending queries were doing bitmap heap scans on a 300GB table. > > Reading the thread I see Andres ask for the "precise conflict" the > user gets -- is there a way I can get that without a datadir? And > to re-frame the original question, are there causes of replication > lag that max_standby_streaming_delay would not be expected to > prevent, that would be resolved by killing long standby queries? > If so, what's the best way to confirm? > > Wyatt > > On Mon, Nov 19, 2018 at 5:46 PM Wyatt Alt > wrote: > > I've been struggling to eliminate replication lag on a > Postgres 9.6.6 instance on Amazon RDS. I believe the lag is > caused by early cleanup conflicts from vacuums on the master, > because I can reliably resolve it by killing long-running > queries on the standby. I most recently saw ten hours of lag > on Saturday and addressed it this way. > > The standby is running with > hot_standby_feedback = on > max_standby_streaming_delay = 5min > max_standby_archive_delay = 30s > > I am not using replication slots on the primary due to > reported negative interactions with pg_repack on large tables. > > My rationale for the first two settings is that > hot_standby_feedback should address my issues almost all the > time, but that max_standby_streaming_delay would sometimes be > necessary as a fallback, for instance in cases of a transient > connection loss between the standby and primary. I believe > these settings are mostly working, because lag is less > frequent than it was when I configured them. > > My questions are, > * Am I overlooking anything in my configuration? > * What would explain lag caused by query conflicts given the > max_standby_streaming_delay setting? Shouldn't those queries > be getting killed? > * Is there any particular diagnostic info I should be > collecting on the next occurrence, to help me figure out the > cause? Note that as I'm on RDS, I don't have direct access to > the datadir -- just psql. > > Thanks for any advice! > Wyatt > > > > -- > El genio es 1% inspiración y 99% transpiración. > Thomas Alva Edison > http://pglearn.blogspot.mx/ > --------------612CC71E0FDB302D01F0E07C Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

Hi Rene,

On 11/19/18 8:46 PM, Rene Romero Benavides wrote:
Not sure about the root cause but I can make these observations and raise some questions:
1) 9.6.6 is five bug fix versions behind
Valid point to raise.
2) 300GB is so big a table, wouldn't make sense to you to partition it ?
2a) or if it's partitioned, doesn't the time of creation or dropping of new partitions match the time of the conflict?
Partitioning is in the works, but none at the moment.

3) can you track long running transactions on the master?
4) what are the isolation levels on master / replica?

Transaction times on the master max out around two minutes. On the replica they are much longer -- numerous 1 - 2 hour transactions per day, and occasional ones as long as 10 - 20 hours. Isolation levels are read committed everywhere.

5) check for active locks in the replica, I guess you should see some blocked transactions during big delays, I've seen this in the past when standby_feedback is turned off.
6) any out of the ordinary messages in the replica's logs? any evidence that has been canceling statements?

I'll make a note to record the active locks next time. I haven't seen anything unusual in the logs during these incidents, but have observed statements getting canceled at other times, which is why I think the config mostly works.

7) are master and replica exactly the same in terms of resources and main parameters?
8) how is performance in both nodes while the big delay is happening? IO / cpu load / etc.

This brings up a good detail I forgot to mention originally. During the last incident, IO utilization on the replica was near 100%, and had been for several hours, which I believe was due to the long queries I canceled.  Now that I think about it, I wonder if the lag may have arisen from IO contention between the query and WAL replay, rather than a query conflict.

Thanks, interesting reading.

Am Mo., 19. Nov. 2018 um 21:46 Uhr schrieb Wyatt Alt <wyatt.alt@gmail.com>:
Sorry, I see now there was a similar question a few days ago:

Two ideas proposed (aside from disconnects):
* Autovacuum is truncating a page on the master and taking an AccessExclusiveLock on the table in use on the replica
* A "pin conflict", which I'm still unfamiliar with.

The user's response says they are in the first bucket, but the argument relies on max_standby_streaming_delay set to -1, while mine is 5 minutes. I need to understand pin conflicts better, but the likely scenario Andrew outlined doesn't apply to me. My offending queries were doing bitmap heap scans on a 300GB table.

Reading the thread I see Andres ask for the "precise conflict" the user gets -- is there a way I can get that without a datadir? And to re-frame the original question, are there causes of replication lag that max_standby_streaming_delay would not be expected to prevent, that would be resolved by killing long standby queries? If so, what's the best way to confirm?

Wyatt

On Mon, Nov 19, 2018 at 5:46 PM Wyatt Alt <wyatt.alt@gmail.com> wrote:
I've been struggling to eliminate replication lag on a Postgres 9.6.6 instance on Amazon RDS. I believe the lag is caused by early cleanup conflicts from vacuums on the master, because I can reliably resolve it by killing long-running queries on the standby. I most recently saw ten hours of lag on Saturday and addressed it this way.

The standby is running with
hot_standby_feedback = on
max_standby_streaming_delay = 5min
max_standby_archive_delay = 30s

I am not using replication slots on the primary due to reported negative interactions with pg_repack on large tables.

My rationale for the first two settings is that hot_standby_feedback should address my issues almost all the time, but that max_standby_streaming_delay would sometimes be necessary as a fallback, for instance in cases of a transient connection loss between the standby and primary. I believe these settings are mostly working, because lag is less frequent than it was when I configured them.

My questions are,
* Am I overlooking anything in my configuration?
* What would explain lag caused by query conflicts given the max_standby_streaming_delay setting? Shouldn't those queries be getting killed?
* Is there any particular diagnostic info I should be collecting on the next occurrence, to help me figure out the cause? Note that as I'm on RDS, I don't have direct access to the datadir -- just psql.

Thanks for any advice!
Wyatt


--
El genio es 1% inspiración y 99% transpiración.
Thomas Alva Edison
http://pglearn.blogspot.mx/

--------------612CC71E0FDB302D01F0E07C--