Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v3Wqq-0003X7-On for pgsql-admin@arkaria.postgresql.org; Tue, 30 Sep 2025 09:40:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1v3Wqo-008AxE-Oz for pgsql-admin@arkaria.postgresql.org; Tue, 30 Sep 2025 09:40:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v3Wqo-008Ax5-Bu for pgsql-admin@lists.postgresql.org; Tue, 30 Sep 2025 09:40:51 +0000 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v3Wqm-000s61-2q for pgsql-admin@postgresql.org; Tue, 30 Sep 2025 09:40:50 +0000 Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-afcb78ead12so995969366b.1 for ; Tue, 30 Sep 2025 02:40:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1759225246; x=1759830046; darn=postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=HfhcL169QO6NSuiMkN6351RhPt8Hm6XrmcZP/EBqRHM=; b=mwI0yYQbWXGhNf5hfBIR6bSdeEyDHC8/0OKWTDOyxUAx/6zjLH6cnljtTLxy8P8ctW jHsCaFjLLVfxYOE0gXWRpP+VxR0G0LYUbi8ob5yB9RUfuena1VkTwvFzp0IXONgW6dck 7IT7uNBO87MwLXKzZto1j6wMKb+t3POt7iJkE+34xiDjzFSFonD9YZqBB3oIH7gPCZOd qAMA/gPZIg8asjSx6xS7vq9L4lcvnc+kIQKhNJFdV9/ZBPWRtByPzgIZKtMyIo3e73cQ fuMiW3dHmMUM2ZC8pwLksXhdkOdMFr/QMlAN9LCEsZFLKpuRPVVl+owBq2zgQ3urhYQT xw6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759225246; x=1759830046; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=HfhcL169QO6NSuiMkN6351RhPt8Hm6XrmcZP/EBqRHM=; b=D9sXpIxP3yz51uGIpG3bFKUQkK9egpfv9kfEiikALof4QxncIiewcAE2ISZdli1jC5 RUbenFVEFjMh5Z/NfkSBZqSPUKHCA01ZWlvwAaAxx0GI0t5/Bpu0hH13fMycEwjzqPOl CnT76duSSbEqs9sPhpJfKXlcK5uFbgUhzyz/4m1z3EQ1L/L+DiPjE5n0+99fMpSQeOJ+ N1AgRxDFMr3ouQe0+E5L1yRKPdxqj32J62MNGtXG2yAycT4tXhj7u7P06xraZuU/6Dr0 NHB8ZF8Ic9jSY/yWgXcP5Pwcy9oYsou4XtsfaCsNDN/kLhCMut9/jJTtZZBBJIKlRli0 epGw== X-Forwarded-Encrypted: i=1; AJvYcCUDCVUf3LaIDbkCimVsBYG4WBaRRkL9RhYnKM81LWFwY/EWO//LGmZE8B8Q5RHSSa8Rua7ZM4U6c+FjAg==@postgresql.org X-Gm-Message-State: AOJu0YwFiGAvgZ/dfOPeX1KSnHOYj4DKxAk0n/E9VzQzWEld6HFZViQL yhBhqywxD3DbmRg4YpDUIxjDQY+F5wxPSELOgs70C3Yv1eCuxZyt1Dj0C490wXqNDRY= X-Gm-Gg: ASbGncvSgm+TA0CugjDpb5ZJtKX8pW0PeQMO85Xt+bVS1FQ0wTxlocQsxj+5zYRA6de KLLH283qJ6ofEyrDwsVnfahhCxDEKj3S84Lifp+/3ph/bg4TC76O4nWe170gVBCDmVQeDGCWUN+ EWAVM6n3TDAsuVY+o5rsdeRsKkQZd9jnwyJ2zVYmcPPzXm3pbEHPMT0qyLEr9RyKhdJ0XHq/XGg 2TbmzbS+Ocmm646j79jCRXEz+NCAybVJZ201Tp/6Zb/obodkbCBOOKw/jkHPjjGOB2fm1iZ/EjU 5ppEzEghnt91es6OYvuVma/31SDDuK0ocTL37b7BQv5HrLzDKc+RNHMYwkLrxzBLA+tS/ray/s6 rvHKiv+2y90jvTYTuRzew4sEWKUjeJdPOjXVpvYm3WIbacF5+eA+bX7ABVM0tgLCBptJt40uviu FnWDK1Ik1Htfw= X-Google-Smtp-Source: AGHT+IHRBUVJIz+BbVBtDn1BfpoWSDYwYmb0fHujchInn5gLdE2Zb5x5nAOsl/Wf0hqWyqUNvDxiow== X-Received: by 2002:a17:906:1642:b0:b37:4f78:55b2 with SMTP id a640c23a62f3a-b374f7855ffmr1315908966b.34.1759225246263; Tue, 30 Sep 2025 02:40:46 -0700 (PDT) Received: from laurenz.albe-K4N0CV00F97414D ([88.116.133.170]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b35446f7681sm1117620966b.58.2025.09.30.02.40.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Sep 2025 02:40:45 -0700 (PDT) Message-ID: Subject: Re: canceling/terminating statement due to conflict with recovery in Replica/DR instances From: Laurenz Albe To: Peter Gram Cc: Ishan joshi , "pgsql-admin@postgresql.org" Date: Tue, 30 Sep 2025 11:40:45 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2 (3.56.2-2.fc42) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2025-09-30 at 09:58 +0200, Peter Gram wrote: > On Tue, 30 Sept 2025 at 08:17, Laurenz Albe wr= ote: > > On Tue, 2025-09-30 at 05:59 +0000, Ishan joshi wrote: > > > There are few large > > > tables for which we asked client to execute queries on DR/Replica ins= tances but > > > these queries are start getting failed with "canceling statement due = to conflict > > > with recovery" and "terminating statement due to conflict with recove= ry" error. > > >=20 > > > As I understand the behavior is correct but we need to get rid of thi= s issue. > > >=20 > > > I gone through the old posts and some documentation and got to know t= hat below > > > parameters can help to reduce this error.=C2=A0 > > >=20 > > > max_standby_streaming_delay=C2=A0 > > > max_standby_archive_delay=C2=A0 > > > hot_standby_feedback =3D off > > >=20 > > > Our queries are running for long period that makes me to set this val= ue to some > > > minutes/hours (lets set 900s) which is not feasible for production as= it will > > > start impacting the replication lag. Also, the queries will fail if i= t reaches > > > to mentioned thresholds. > > >=20 > > > If I set these parameters to "-1" (disable) then there will be direct= impact on > > > replication lag which will impact further queries on replica node and= DR cluster. > > >=20 > > > Can you please guide If any other better solution present for such sc= enario? > >=20 > > No, there is no better solution. > >=20 > > If you need both no delay and no canceled queries, the only clean solut= ion is > > to have two standby servers. > > Could you elaborate on why two or more standby servers would help in this= case ?=20 One of the standby servers would have "max_standby_streaming_delay =3D 0" o= r "hot_standby =3D off", that one would be for high availability. The other one would have "max_standby_streaming_delay =3D -1" and would be = used for queries. Yours, Laurenz Albe