Re: Queries are failing on standby server

From: Keith Fiske <keith(dot)fiske(at)crunchydata(dot)com>
To: Fernando Hevia <fhevia(at)gmail(dot)com>
Cc: Wasim Devale <wasimd60(at)gmail(dot)com>, Scott Ribe <scott_ribe(at)elevated-dev(dot)com>, Ron Johnson <ronljohnsonjr(at)gmail(dot)com>, pgsql-admin <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Queries are failing on standby server
Date: 2024-07-26 02:59:06
Message-ID: CAODZiv6GJ+6L+mE=0Dx3B1eDpqZiTvO-xd=USx3x+G-D4o6Lzg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Thu, Jul 25, 2024 at 7:57 PM Fernando Hevia <fhevia(at)gmail(dot)com> wrote:

> Hi Wasim,
>
> 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 server. It happens that when you run queries on a hot
> standby, the replication is temporarily paused in order to not modify data
> the running queries on the standby server need. 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 master happens to fail while the replica is delayed you
> end up with data loss.
> To avoid having a standby server lagging too far behind Postgres will
> cancel long running queries on the replica. The
> parameter max_standby_streaming_delay defines the maximum replication delay
> the standby will tolerate. Default is 30 seconds. Increase 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.
>
> A working alternative is to have one standby server exclusively for
> replication purposes and another standby for reporting/read-only queries
> where you can increase the max_standby_streaming_delay to accommodate your
> long running queries. Of course, this will require additional computing and
> storage resources.
>
> Cheers,
> Fernando.
>
>>
>>>
This is all true, but the hot_standby_feedback option is the way to get
around needing to worry about replication delay all together. As far as how
it affects VACUUM, it's no different to how running those same queries on
the primary would affect it. The reason I mention it is that people think
that moving queries to the replica takes away all the effects of running
them on the primary. It takes away the load of the query, but there are
side effects that still have to be managed. Either of the options mentioned
are fine to do as long as you know the consequences of them.

--
Keith Fiske
Senior Database Engineer
Crunchy Data - http://crunchydata.com

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Keith Fiske 2024-07-26 03:01:28 Re: How to detect if a postgresql gin index is bloated
Previous Message Fernando Hevia 2024-07-25 23:57:39 Re: Queries are failing on standby server