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 1v3TfZ-00GrJF-T2 for pgsql-admin@arkaria.postgresql.org; Tue, 30 Sep 2025 06:17:01 +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 1v3TfW-006bqi-JC for pgsql-admin@arkaria.postgresql.org; Tue, 30 Sep 2025 06:16:59 +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 1v3TfW-006bqa-6Z for pgsql-admin@lists.postgresql.org; Tue, 30 Sep 2025 06:16:58 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v3TfU-000qCb-0U for pgsql-admin@postgresql.org; Tue, 30 Sep 2025 06:16:58 +0000 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-62f24b7be4fso9802981a12.0 for ; Mon, 29 Sep 2025 23:16:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1759213014; x=1759817814; darn=postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=F8dRj4z2725th4cJt+5ok1vTgrnRU4Fn90C69dGi7dQ=; b=DvdwX24e40zOU8MpPtJed3k5ydURWXYFdz4DsMufqxO1CUZKjRU7iWOInmWrG9xXMQ Imt+PdomBbyi4Sq1p3Y0MLimfZR84RDHuveDYEP4AZz5fegyBWMkV7x2nI3Ii5yhxe8J lvWFWqEChjZNtWhwWVMq9gW7M7vv9m/e8UE3zmAj0Ue5BBZFPDTagRCliLQtiXgwPZEV XXow66FDjD6TP+RuML1QhIuzB3qVEmEbRFK6xmv3yy3wDByaOSA/tChO+nnh95Tr0oDO ffqHrr1nepuezAK/pJJeWJNdS5wqzpiaDj2v7xiukWVawtMO/ucz16cOV+G8uFV+A9J9 ztIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759213014; x=1759817814; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=F8dRj4z2725th4cJt+5ok1vTgrnRU4Fn90C69dGi7dQ=; b=EY4B1tmMYOPzlRIITrNGPk8hWr8G6kUvS6QtLCJ2oRCWZzEaxtW98N7qCjN0uF19xN MwV6Rp58ruQuVfb4a+XUe1J4cu0dOgXxzi1Mgzk4BiRzXw+0epkhlwAdgiR66pOe7Cc8 WdH/ZnHxHV0PmV/xa0u/SI6CJRj3IllnYDPKkiK8J9xvBH4pAN/7iy61Sp3iK24VMKfw 0C73m72MfntvH4CK/DY2sqVeYd9yjEF+6/7xEvsyR10OffMEIh7Ob28keSj7b8dCMn3n GxcmPbb99cIPsrSw75eKaFRV+eDE4J7UczJNmrcvURbXA2U84ihtINkyF7mbU6nJMWad eiRA== X-Forwarded-Encrypted: i=1; AJvYcCV1VieQKWwZqp6w09se5gQV7id4G3p4VbgALlgEvIyJEhpeF/30qp6cvj9EuWJm/ELkhLD3F4o9IkZBSQ==@postgresql.org X-Gm-Message-State: AOJu0YxblLtVzmXskxkGVdtGTiqrHQ2w7bxbbe5RvTZPSkK8cCwZ/Rgr JExpsBdJ1HbEePDPR9mAO6+dYyr0gUWh64gV6FuzXtvb8ej0dT8f0aQE0f+sUY8JeJE= X-Gm-Gg: ASbGnctt+WkbJJ2ir3UFEoA7ekhlWkSoXWf1d8FwzVX8162R/zAaHbqwpdJ0hCkiLu2 l3Jm8jBD48xvuEy5Kte5V7YWoO7lYd/JtjnUxJY556KcXgMqPOUn8T+U5ZlbT4eyYxI/D9s+c+r awHXAn6+6tBgNfqcLFO6Yi/+NGhQ54Xjwcvaprn4ewC2+pcg2UnFywEPkPzk+mr5EYRcBOjUVdA MTGycci7NiHmz/pBQypN87DvtjorGGu60NaV6vvh9EYKIm+7tTjEek3sXPADmuLpzfPpz5EIcAl PsEnEjU8VSHDZ/WBuaEvtniFuc47ypYNqdU/B9BLK6WNDXue6IYAoK9Vm0XGcw0HZ0IHmZuK0OX Xt4o+QGbahjtdth5rQrVJ8vL3gzDOQQiSUzgCquCif69FhP20HwET6QPv8DOpAmShdzLa1c4Wjw == X-Google-Smtp-Source: AGHT+IH7mqvHujGLjHxFUnLLdkCAK8RY1aHeZvPvCv4+IsUOpBOyZsOM4s4qYDFd4VvqobTC+G9lcg== X-Received: by 2002:a05:6402:1d54:b0:634:b63f:275f with SMTP id 4fb4d7f45d1cf-634b63f2c1bmr14461312a12.3.1759213014397; Mon, 29 Sep 2025 23:16:54 -0700 (PDT) Received: from laurenz.albe-K4N0CV00F97414D ([41.66.98.133]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-63667046ec1sm534496a12.30.2025.09.29.23.16.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Sep 2025 23:16:54 -0700 (PDT) Message-ID: Subject: Re: canceling/terminating statement due to conflict with recovery in Replica/DR instances From: Laurenz Albe To: Ishan joshi , "pgsql-admin@postgresql.org" Date: Tue, 30 Sep 2025 08:16:53 +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 05:59 +0000, Ishan joshi wrote: > We are using Postgresql 16.9 in production and with large database about = 25TB > of size. We have patroni setup with replica instance and DR patroni setup= with > patroni streaming. >=20 > We have high volume and frequent commit in the database. There are few la= rge > tables for which we asked client to execute queries on DR/Replica instanc= es but > these queries are start getting failed with "canceling statement due to c= onflict > with recovery" and "terminating statement due to conflict with recovery" = error. >=20 > As I understand the behavior is correct but we need to get rid of this is= sue. >=20 > I gone through the old posts and some documentation and got to know that = 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 value t= o 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 it re= aches > to mentioned thresholds. >=20 > If I set these parameters to "-1" (disable) then there will be direct imp= act 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 scenar= io? No, there is no better solution. You can reduce replication conflicts by turning on "hot_standby_feedback" a= nd by turning off "vacuum_truncate", but you probably won't be able to get rid of= all replication conflicts. You can either have a small replay delay and canceled queries or no cancele= d queries, but the occasional replay delay. If you need both no delay and no canceled queries, the only clean solution = is to have two standby servers. Yours, Laurenz Albe