Re: Speedup of relation deletes during recovery - Mailing list pgsql-hackers

From Andres Freund
Subject Re: Speedup of relation deletes during recovery
Date
Msg-id 20180615174504.cf2ba4p6xuu36hn6@alap3.anarazel.de
Whole thread Raw
In response to Re: Speedup of relation deletes during recovery  (Fujii Masao <masao.fujii@gmail.com>)
Responses Re: Speedup of relation deletes during recovery
Re: Speedup of relation deletes during recovery
List pgsql-hackers
Hi,

We just had a customer hit this issue. I kind of wonder whether this
shouldn't be backpatched: Currently the execution on the primary is
O(NBuffers * log(ndrels)) whereas it's O(NBuffers * ndrels) on the
standby - with a lot higher constants to boot.  That means it's very
easy to get into situations where the standy starts to lag behind very significantly.

> --- a/src/backend/access/transam/twophase.c
> +++ b/src/backend/access/transam/twophase.c
> @@ -1445,6 +1445,7 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
>      int            ndelrels;
>      SharedInvalidationMessage *invalmsgs;
>      int            i;
> +    SMgrRelation *srels = NULL;
>  
>      /*
>       * Validate the GID, and lock the GXACT to ensure that two backends do not
> @@ -1534,13 +1535,16 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
>          delrels = abortrels;
>          ndelrels = hdr->nabortrels;
>      }
> +
> +    srels = palloc(sizeof(SMgrRelation) * ndelrels);
>      for (i = 0; i < ndelrels; i++)
> -    {
> -        SMgrRelation srel = smgropen(delrels[i], InvalidBackendId);
> +        srels[i] = smgropen(delrels[i], InvalidBackendId);
>  
> -        smgrdounlink(srel, false);
> -        smgrclose(srel);
> -    }
> +    smgrdounlinkall(srels, ndelrels, false);
> +
> +    for (i = 0; i < ndelrels; i++)
> +        smgrclose(srels[i]);
> +    pfree(srels);

This code is now duplicated three times - shouldn't we just add a
function that encapsulates dropping relations in a commit/abort record?

Greetings,

Andres Freund


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #15237: I got "ERROR: source for a multiple-column UPDATE item must be a sub-SELECT or ROW() expression"
Next
From: Teodor Sigaev
Date:
Subject: Re: Speedup of relation deletes during recovery