Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1guCGW-000501-GK for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Feb 2019 08:21:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1guCGV-0008Ho-8i for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Feb 2019 08:21:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1guCGU-0008Hh-S4 for pgsql-hackers@lists.postgresql.org; Thu, 14 Feb 2019 08:21:03 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1guCGR-0008FF-KL for pgsql-hackers@lists.postgresql.org; Thu, 14 Feb 2019 08:21:01 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 7421C21CB00F; Thu, 14 Feb 2019 11:20:57 +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 [192.168.27.237] (gw.postgrespro.ru [93.174.131.141]) (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 49C8821CAED1; Thu, 14 Feb 2019 11:20:57 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1550132457; bh=ZqDXs6AM9QGAb8m03z1IsMfxUpYuGWqIDC3LiRSWXW8=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=JAUcCjwuYuSk/t3XCW29Ezd5VTT1gvZNPGap3un0o//ufD8ni4Sd91XlPNnxClsr7 CBASamZDbVvMWVibkLtOH0Ss3bgNNriV0o11LuVe+GqtUWy4aj1/05LzU887heAKRD RX5iws/tLyhhEu8J/oRmd1PzID+kMWIv2oUHMkAE= Subject: Re: [PATCH] xlogreader: do not read a file block twice To: Michael Paquier Cc: Grigory Smolkin , pgsql-hackers@lists.postgresql.org References: <2ddf4a32-517e-d6f4-d992-4a63b6035bfd@postgrespro.ru> <87e30af6-f85a-dc95-4574-95cded028786@postgrespro.ru> <20190212042300.GL1475@paquier.xyz> <1fa0c9fe-32a5-3ebd-e9c2-b5e2c9abc03e@postgrespro.ru> <20190214065156.GE2366@paquier.xyz> From: Arthur Zakirov Message-ID: <7eaccd53-ea89-e0cf-b718-80e3f3fc3abf@postgrespro.ru> Date: Thu, 14 Feb 2019 11:20:56 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 In-Reply-To: <20190214065156.GE2366@paquier.xyz> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 14.02.2019 09:51, Michael Paquier wrote: > Now I don't actually agree that this qualifies as a bug fix. As > things stand, a page may finish by being more than once if what has > been read previously equals what is requested, however this does not > prevent the code to work correctly. The performance gain is also > heavily dependent on the callback reading a page and the way the WAL > reader is used. How do you actually read WAL pages in your own > plugin with compressed data? It begins by reading a full page once, > then it moves on to a per-record read after making sure that the page > has been read? Yes, an application reads WAL pages wholly at a time. It is done within SimpleXLogPageRead() (it is a read_page callback passed to XLogReaderAllocate()). It returns XLOG_BLCKSZ. Here is the part of the code, not sure that it will be useful though: SimpleXLogPageRead(...) { ... targetPageOff = targetPagePtr % private_data->xlog_seg_size; ... if (gzseek(private_data->gz_xlogfile, (z_off_t) targetPageOff, SEEK_SET) == -1) ... if (gzread(private_data->gz_xlogfile, readBuf, XLOG_BLCKSZ) != XLOG_BLCKSZ) ... return XLOG_BLCKSZ; } So we read whole page with size XLOG_BLCKSZ. The full code: https://github.com/postgrespro/pg_probackup/blob/c052651b8c8864733bcabbc2660c387b792229d8/src/parsexlog.c#L1074 Here is the little optimization I made. Mainly I just add a buffer to store previous read page: https://github.com/postgrespro/pg_probackup/blob/c052651b8c8864733bcabbc2660c387b792229d8/src/parsexlog.c#L1046 -- Arthur Zakirov Postgres Professional: http://www.postgrespro.com Russian Postgres Company