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 1gMkLq-0006Hj-Em for pgsql-admin@arkaria.postgresql.org; Wed, 14 Nov 2018 01:52:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gMkLo-0002vg-4B for pgsql-admin@arkaria.postgresql.org; Wed, 14 Nov 2018 01:52:16 +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 1gMkLn-0002vZ-Ko for pgsql-admin@lists.postgresql.org; Wed, 14 Nov 2018 01:52:15 +0000 Received: from mtaout003-public.msg.strl.va.charter.net ([68.114.190.28]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gMkLk-0004bR-IP for pgsql-admin@lists.postgresql.org; Wed, 14 Nov 2018 01:52:14 +0000 Received: from impout002 ([68.114.189.17]) by mtaout003.msg.strl.va.charter.net (InterMail vM.9.00.023.01 201-2473-194) with ESMTP id <20181114015211.CHCM7355.mtaout003.msg.strl.va.charter.net@impout002>; Tue, 13 Nov 2018 19:52:11 -0600 Received: from cerberus.crazybean.net ([24.151.10.150]) by impout002 with charter.net id zdsB1y0053EE3TL01dsB66; Tue, 13 Nov 2018 19:52:11 -0600 X-Authority-Analysis: v=2.2 cv=C6eZ8UH+ c=1 sm=1 tr=0 a=D2HTw/M6/8MmcHighGO7rg==:117 a=D2HTw/M6/8MmcHighGO7rg==:17 a=xqWC_Br6kY4A:10 a=JHtHm7312UAA:10 a=Rh5JslpUAAAA:8 a=sTNdbjK_bbZahpUK_BQA:9 a=QEXdDO2ut3YA:10 a=oIfrFNJ-AAAA:8 a=9IKvQKQCqOnEg6DelUAA:9 a=MAwdpvHtF9wSNQ-4:21 a=_W_S_7VecoQA:10 a=CRjGpuKUiiIuQkCM3vJl:22 a=Cg2NcamS17xU0rR7el6q:22 Received: from [IPv6:2001:470:e117:4:c8fe:67a8:9b94:f1cf] (2001:470:e117:4:c8fe:67a8:9b94:f1cf [IPv6:2001:470:e117:4:c8fe:67a8:9b94:f1cf]) by cerberus.crazybean.net (OpenSMTPD) with ESMTPSA id 58e56b35 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Tue, 13 Nov 2018 20:52:11 -0500 (EST) From: Rui DeSousa Message-Id: <739822AC-E20F-493B-8B4F-8AF78A8276D0@crazybean.net> Content-Type: multipart/alternative; boundary="Apple-Mail=_3EBBD942-1CAF-4EC3-A03F-6D7661344875" Mime-Version: 1.0 (Mac OS X Mail 12.1 \(3445.101.1\)) Subject: Re: PostgreSQL 10.5 : Logical replication timeout results in PANIC in pg_wal "No space left on device" Date: Tue, 13 Nov 2018 20:52:10 -0500 In-Reply-To: <48415b2a-ea0f-cf5e-1145-17e8797a6e79@matrix.gatewaynet.com> Cc: pgsql-admin@lists.postgresql.org To: Achilleas Mantzios References: <838a3914-a078-88eb-ee5e-4059b7d14620@matrix.gatewaynet.com> <0BBC4BB3-4A59-4040-B065-82D09268A4F7@crazybean.net> <48415b2a-ea0f-cf5e-1145-17e8797a6e79@matrix.gatewaynet.com> X-Mailer: Apple Mail (2.3445.101.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_3EBBD942-1CAF-4EC3-A03F-6D7661344875 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Nov 13, 2018, at 11:06 AM, Achilleas Mantzios = wrote: >=20 > On 13/11/18 5:35 =CE=BC.=CE=BC., Rui DeSousa wrote: >>=20 >>=20 >>> On Nov 13, 2018, at 7:00 AM, Achilleas Mantzios = > = wrote: >>>=20 >>> Is there a way for the WAL receiver to not have detected the = termination of the replication stream? >>=20 >> The teardown of the network socket on the upstream server should send = a reset packet to the downstream server and at that point the WAL = receiver would close its connection. Is there any firewalls, router, = rules, etc between the nodes that could have dropped the packet?=20 >=20 > No >=20 If both nodes are up and able to communicate with each other then the OS = should teardown the connection; why is that not happening? You stated = that you=E2=80=99re in the cloud; cloud providers use a software network = and all endpoints have ACLs =E2=80=94 a.k.a firewall. I would also check = to see if iptables is running=E2=80=A6 it on by default. Have there been changes to how you deploy new ACLs, etc?=20 The fact that WAL sender terminated and WAL receiver did not; points to = the WAL receiver not being able to communicate with the upstream server. >>=20 >>>=20 >>> Shouldn't normally the WAL receiver detect this and try again in = wal_retrieve_retry_interval ? >>=20 >> Not really=E2=80=A6 if the connection has already been torn down; the = upstream server would send another reset packet on the next request and = in this case it would. However, if request packets at not reaching the = upstream server; i.e. due to firewall silently dropping the packets = (personally I believe firewall should always set reset packets to = friendly hosts) then what happens is the TCP/IP send queue builds up = with the requests packets instead =E2=80=94 a t this point waiting on = the OS to terminate the connection which can day or two depending on = your TCP/IP setting. >>=20 >=20 > Again no dropping, no firewall. >=20 Again, if both nodes are up and are able to communicate then the this = should get resolved on its own. >> What you want to use instead is wal_receiver_timeout to detect the = given case where upstream server either no longer exists or the = firewall, etc is silently dropping packets. >=20 > Once again from my original message : > "while setting up logical replication since August we had seen early = on the need to increase max_receiver_timeout and max_sender_timeout from = 60sec to 5mins" >=20 > So with wal_receiver_timeout=3D'5 min', the receiver never detected = any timeout. >=20 It should have reached the timeout and the connection should be torn = down. It could be that the send queue is backed up and Postgres is hung = on trying to teardown the connection. Again, network related issue. I=E2=80=99ve actually ran into this issue before; where I was unable to = terminate an idle session from an application node that had an open = transaction. The TCP/IP send queue was backlogged thus it would not = terminate; one might consider this a bug or not. The application server = was not reachable due to firewall dropping the connection and not = sending a reset packet on further attempts to communicate with the = application server; I had to get a network admin to drop the connection = as bouncing Postgres was not an option on a production system and kill = -9 is a bad idea too. =20 Assuming this is going to happen again =E2=80=94 I would advise you to = get from both nodes the state of connection and tcp/ip queue information = from netstat. If you can also to a tcpdump on the connection to see = what each of the nodes is doing that would give you more insight. I would also advise looking into TCP/IP keep alive. --Apple-Mail=_3EBBD942-1CAF-4EC3-A03F-6D7661344875 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Nov 13, 2018, at 11:06 AM, Achilleas Mantzios <achill@matrix.gatewaynet.com> wrote:

=20 =20
On 13/11/18 5:35 =CE=BC.=CE=BC., Rui = DeSousa wrote:


On Nov 13, 2018, at 7:00 AM, Achilleas = Mantzios <achill@matrix.gatewaynet.com> wrote:

Is there a way for the WAL = receiver to not have detected the termination of the replication stream?

The teardown of the network socket on the upstream server should send a reset packet to the downstream server and at that point the WAL receiver would close its connection. =  Is there any firewalls, router, rules, etc between the nodes that could have dropped the packet?

No


If both nodes are up and able to communicate with = each other then the OS should teardown the connection; why is that not = happening?  You stated that you=E2=80=99re in the cloud; cloud = providers use a software network and all endpoints have ACLs =E2=80=94 = a.k.a firewall. I would also check to see if iptables is running=E2=80=A6 = it on by default.

Have there been = changes to how you deploy new ACLs, etc? 

The fact that WAL sender terminated and WAL = receiver did not; points to the WAL receiver not being able to = communicate with the upstream server.



Shouldn't normally the WAL receiver detect this and try again in wal_retrieve_retry_interval = ?

Not really=E2=80=A6 if the connection has already = been torn down; the upstream server would send another reset packet on the next request and in this case it would.  However, if = request packets at not reaching the upstream server; i.e. due to firewall silently dropping the packets (personally I believe firewall should always set reset packets to friendly hosts) then what happens is the TCP/IP send queue builds up with the requests packets instead =E2=80=94 a t this point waiting on the = OS to terminate the connection which can day or two depending on your TCP/IP setting.


Again no dropping, no firewall.


Again, if both nodes are up and are able to = communicate then the this should get resolved on its own.

What you want to use instead is = wal_receiver_timeout to detect the given case where upstream server either no longer exists or the firewall, etc is silently dropping packets.

Once again from my original message :
"while setting up logical replication since August we had seen early on the need to increase max_receiver_timeout and max_sender_timeout from 60sec to 5mins"

So with wal_receiver_timeout=3D'5 min', the receiver never detected any timeout.


It should have reached the timeout and the = connection should be torn down.  It could be that the send queue is = backed up and Postgres is hung on trying to teardown the connection. =  Again, network related issue.

I=E2=80=99ve actually ran into this issue before; = where I was unable to terminate an idle session from an application node = that had an open transaction.  The TCP/IP send queue was backlogged = thus it would not terminate; one might consider this a bug or not. =  The application server was not reachable due to firewall dropping = the connection and not sending a reset packet on further attempts to = communicate with the application server; I had to get a network admin to = drop the connection as bouncing Postgres was not an option on a = production system and kill -9 is a bad idea too.  

Assuming this is going to happen = again =E2=80=94 I would advise you to get from both nodes the state of = connection and tcp/ip queue information from netstat.   If you can = also to a tcpdump on the connection to see what each of the nodes is = doing that would give you more insight.

I would also advise looking into TCP/IP = keep alive.

= --Apple-Mail=_3EBBD942-1CAF-4EC3-A03F-6D7661344875--