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 1sXDBj-002RwJ-GH for pgsql-admin@arkaria.postgresql.org; Fri, 26 Jul 2024 05:08:19 +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 1sXDBh-005ObB-SE for pgsql-admin@arkaria.postgresql.org; Fri, 26 Jul 2024 05:08:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sXDBh-005Ob1-Gh for pgsql-admin@lists.postgresql.org; Fri, 26 Jul 2024 05:08:17 +0000 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sXDBe-001UHA-L1 for pgsql-admin@postgresql.org; Fri, 26 Jul 2024 05:08:16 +0000 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a7a83a968ddso161570566b.0 for ; Thu, 25 Jul 2024 22:08:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20230601.gappssmtp.com; s=20230601; t=1721970493; x=1722575293; 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=bu40LCZNh59GOf5bzeZYTzTonvQ/mYopbj8Lgf/Svtk=; b=pgfQ6STajFZMgmnjhVogUq3nyb7Z+TtsvjfqF1XqDpR4JnXAhe8TSVxmu6SPGmFzwg XavYGiERiZPhCbnOeoWhgZWEWmM5NTMe8SDIQlE2iDwkufzgBC9UjSRFtR7rnre6nQeZ 46lb9BlsrxYydBtuXcXz0X+OwFxEVURNLQjuWy6uW4n2nvQl7n+Dk5+JdhSmMzhDpN2T 2h+jGzcKFlMRrjXYCwdOEtz8CYzNw5J4I19E5kHN4nUWbathQ145mYAvwuELoTAsuFu5 Ycqobg06WBx8V3GiAKu1NF6LirpMhZAI3BVnDJyAUIKx0QpaGvv1x7SztkQdtjWNoOm1 DH7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721970493; x=1722575293; 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=bu40LCZNh59GOf5bzeZYTzTonvQ/mYopbj8Lgf/Svtk=; b=PpgJpnHjas9iTKZNjuUkQb/ZF5QTZrGHhqSn6FEGGSiUCq6VPCduBMN0Yb4hPCeULt crEKrgklrl7nA0inM1/pyIeL5PL7jtlT+IiBQmwS6EExZIV1H58CaThF1UQSwIXvhs47 AE0XjNiRnv6BS3ZBOOeZDawiXEm6ZklN+etjb6/Cqe49JBnqojk8Dt0dueTzZ9mBQncv qLDjxwTXH0wXoygk84MZkTsHqBp+q1CyClA24sqHrxoi0CLjQ4g9rcUy++BCDUc7y+2t Wx3A3Wns55+mlpx9jjrQTYkn9vv3QjjhGRURvqC2e1sjLgQWHY85lR89AmsL9Fe0xaX9 PfBg== X-Forwarded-Encrypted: i=1; AJvYcCWLBGWYFaroLKFajs6BumE2G8Lf3nfLQtc+nwKTiLUf3I6uOTrqFtCVAH9aFp7WFcBaoEbB4JbY6OMm+9GpS5+KXUEXwNd6Okp+VA== X-Gm-Message-State: AOJu0YwHEyJjT5OoSd0JVTh9z9xkNK7CjQBoAFEupDmUY+5MwVWEmbam 2K1szA84JOU6EO0uJK3tPSk4mPdLomHt70V3ZtFuWluF5ZGrx59r9KwgS5xIEaQ= X-Google-Smtp-Source: AGHT+IEgGjmDJ/fBYujXpBVPgUOeNJREyB9RoFjhtSf5aiUTBErSSkDgjTHP6TF5Qak58ZzmxQENPw== X-Received: by 2002:a17:907:2d8e:b0:a7a:a763:8430 with SMTP id a640c23a62f3a-a7acb4b328dmr301435666b.31.1721970492500; Thu, 25 Jul 2024 22:08:12 -0700 (PDT) Received: from dynamic-pd01.res.v6.highway.a1.net ([2001:871:5e:1fa7:3178:1dcd:ea7a:2f81]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7acadb985csm133994166b.212.2024.07.25.22.08.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 22:08:12 -0700 (PDT) Message-ID: Subject: Re: Queries are failing on standby server From: Laurenz Albe To: Keith Fiske , Fernando Hevia Cc: Wasim Devale , Scott Ribe , Ron Johnson , pgsql-admin Date: Fri, 26 Jul 2024 07:08:11 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.3 (3.52.3-1.fc40) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 2024-07-25 at 22:59 -0400, Keith Fiske wrote: > On Thu, Jul 25, 2024 at 7:57=E2=80=AFPM Fernando Hevia = wrote: > > I think you might have misinterpreted the explanation given to you. The= cancellation of the > > query on the standby server isn't related to the load on the primary se= rver. It happens that > > when you run queries on a hot standby, the replication is temporarily p= aused in order to not > > modify data the running queries on the standby server need. Replication (applying the WAL information) is only paused if there is a con= flict. Even when replay is paused, the WAL is still replicated to the standby and = piles up there. > > Once the queries end, replication resumes. > > The problem of this behaviour is that the standby server starts to fall= behind in relation > > to the master, a scenario which presents a risky condition: if the mast= er happens to fail > > while the=C2=A0replica is delayed you end up with data loss. No, because the WAL is replayed. What happens is that promoting the standby will take longer if it has to re= play a lot of WAL. > > To avoid having a standby server lagging too far behind Postgres will c= ancel long running > > queries on the replica. The parameter=C2=A0max_standby_streaming_delay = defines the maximum > > replication delay the standby will tolerate. Default is 30 seconds. Inc= rease the value to > > allow for longer running queries on the standby server bearing in mind = that you could end > > up with data loss if the master fails at the wrong moment. Yes, increasing "max_standby_streaming_delay" is the correct solution. You can set it to -1 to prevent any queries on the standby from bein cancel= led. > > A working alternative is to have one standby server exclusively for rep= lication purposes > > and another standby for reporting/read-only queries where you can incre= ase the > > max_standby_streaming_delay to accommodate your long running queries. O= f course, this will > > require additional computing and storage resources. That is good advice. > > >=20 > This is all true, but the hot_standby_feedback option is the way to get a= round needing to > worry about replication delay all together. No, because there are other kinds of replication conflicts. The most frequ= ent are: - lock conflicts They can occur whenever an ACCESS EXCLUSIVE lock on the primary conflicts= with a query on the standby. The most frequent cause is VACUUM truncation (wh= ich can be disabled for individual tables). - buffer pin conflicts It depends on the workload if you get them, but you cannot get rid of the= m. Yours, Laurenz Albe