Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jlzYZ-0001sy-25 for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jun 2020 18:46:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jlzYX-0007KC-9a for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jun 2020 18:46:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jlzYW-0007K5-Ua for pgsql-hackers@lists.postgresql.org; Thu, 18 Jun 2020 18:46:33 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jlzYT-0002SH-F1 for pgsql-hackers@postgresql.org; Thu, 18 Jun 2020 18:46:32 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 70C1521C6DD3; Thu, 18 Jun 2020 21:46:28 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from mail.postgrespro.ru (unknown [93.174.131.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 3879B21C6DCF; Thu, 18 Jun 2020 21:46:28 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1592505988; bh=ImUIyITXqmSpkyO57yyxAubG0T/WDLdl0MT6PmT6F5s=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=qcOMbvpqqFkfCN5dkE7gvBDMya5RwTuqgYxz38ajQ09QLfdirir2evDq4fzqf6t01 af14fEJXRl1A/jx4QLLOU9u+5qcwj58mBOw1hmNIczbHBTaeeSGr3GXhXTeZ9lVBDy U/OGuRHPSZ4F87uUlaJeASAMjaTQRGSFYvy9Orlg= MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=_1e7043299a5e4d2debc497d43e49daef" Content-Transfer-Encoding: 8bit Date: Thu, 18 Jun 2020 21:46:28 +0300 From: Alexey Kondratov To: Michael Paquier Cc: Kyotaro Horiguchi , andres@anarazel.de, dim@tapoueh.org, pgsql-hackers@postgresql.org, simon@2ndquadrant.com Subject: Re: Physical replication slot advance is not persistent In-Reply-To: <20200616072727.GA2361@paquier.xyz> References: <20200609171904.kpltxxvjzislidks@alap3.anarazel.de> <82163ef4a380c5255e5004659d02559e@postgrespro.ru> <20200610065353.GA358163@paquier.xyz> <20200610.173844.78906193765823414.horikyota.ntt@gmail.com> <876a782d320a52b0c54d6d48372de17d@postgrespro.ru> <20200616072727.GA2361@paquier.xyz> User-Agent: Roundcube Webmail/1.4.0 Message-ID: <0a14a258081aea401222498d402d129b@postgrespro.ru> X-Sender: a.kondratov@postgrespro.ru List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --=_1e7043299a5e4d2debc497d43e49daef Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8; format=flowed On 2020-06-16 10:27, Michael Paquier wrote: > On Wed, Jun 10, 2020 at 08:57:17PM +0300, Alexey Kondratov wrote: >> New test reproduces this issue well. Left it running for a couple of >> hours >> in repeat and it seems to be stable. > > Thanks for testing. I have been thinking about the minimum xmin and > LSN computations on advancing, and actually I have switched the > recomputing to be called at the end of pg_replication_slot_advance(). > This may be a waste if no advancing is done, but it could also be an > advantage to enforce a recalculation of the thresholds for each > function call. And that's more consistent with the slot copy, drop > and creation. > Sorry for a bit late response, but I see a couple of issues with this modified version of the patch in addition to the waste call if no advancing is done, mentioned by you: 1. Both ReplicationSlotsComputeRequiredXmin() and ReplicationSlotsComputeRequiredLSN() may have already been done in the LogicalConfirmReceivedLocation() if it was a logical slot. It may be fine and almost costless to do it twice, but it looks untidy for me. 2. It seems that we do not need ReplicationSlotsComputeRequiredXmin() at all if it was a physical slot, since we do not modify xmin in the pg_physical_replication_slot_advance(), doesn't it? That's why I wanted (somewhere around v5 of the patch in this thread) to move all dirtying and recomputing calls to the places, where xmin / lsn slot modifications are actually done — pg_physical_replication_slot_advance() and LogicalConfirmReceivedLocation(). LogicalConfirmReceivedLocation() already does this, so we only needed to teach pg_physical_replication_slot_advance() to do the same. However, just noted that LogicalConfirmReceivedLocation() only does ReplicationSlotsComputeRequiredLSN() if updated_xmin flag was set, which looks wrong from my perspective, since updated_xmin and updated_restart flags are set separately. That way, I would solve this all as per attached, which works well for me, but definitely worth of a better testing. Regards -- Alexey Kondratov Postgres Professional https://www.postgrespro.com Russian Postgres Company --=_1e7043299a5e4d2debc497d43e49daef Content-Transfer-Encoding: base64 Content-Type: text/x-diff; name=slots-advancing.diff Content-Disposition: attachment; filename=slots-advancing.diff; size=1650 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL3JlcGxpY2F0aW9uL2xvZ2ljYWwvbG9naWNhbC5jIGIv c3JjL2JhY2tlbmQvcmVwbGljYXRpb24vbG9naWNhbC9sb2dpY2FsLmMKaW5kZXggNjE5MDJiZTNi MC4uMmNlYjA3ODQxOCAxMDA2NDQKLS0tIGEvc3JjL2JhY2tlbmQvcmVwbGljYXRpb24vbG9naWNh bC9sb2dpY2FsLmMKKysrIGIvc3JjL2JhY2tlbmQvcmVwbGljYXRpb24vbG9naWNhbC9sb2dpY2Fs LmMKQEAgLTEwODEsOCArMTA4MSwxNCBAQCBMb2dpY2FsQ29uZmlybVJlY2VpdmVkTG9jYXRpb24o WExvZ1JlY1B0ciBsc24pCiAJCQlTcGluTG9ja1JlbGVhc2UoJk15UmVwbGljYXRp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