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 1jJKXC-0001vx-Vy for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2020 17:18:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jJKXB-0001OZ-Se for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2020 17:18:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJKXB-0001Ld-Lu for pgsql-hackers@lists.postgresql.org; Tue, 31 Mar 2020 17:18:41 +0000 Received: from mail-qk1-x744.google.com ([2607:f8b0:4864:20::744]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jJKX9-0003ED-Gq for pgsql-hackers@lists.postgresql.org; Tue, 31 Mar 2020 17:18:40 +0000 Received: by mail-qk1-x744.google.com with SMTP id j4so23805303qkc.11 for ; Tue, 31 Mar 2020 10:18:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=jHM+XBmQ6ZTO6XPJIak8YtvTur1P6I0I8T4l/ZP+lVM=; b=TdVM0CQCtQOaWdmqGmA8DurBKpZPNOvgqQek5Szw5ewm85Bu3ysiiQfFjcNTI7odiV zW44GyZz8NCUZZJjoW/9nX3qyJYatPsclkCE0xpJ4utHwy71mlI0XzT55GqAxqiMjO8t KhnIsMQgZMq6j96bE1U8q+krIkXlN/ooIuoLBBII7fP64X9BdAOXTgxd9PXVG1bqKS6Z C4jQXXbzYdNyqtJ2tGorjph5DY8qTr/o2Ly1v5jGjQm+K5KVxOHNdKzWCUSMrDrCF3lw 49Mur9E3i+1X2hytHOv2NGNASaWXeurZQnvbH0NEFudQUFCqVzGUQD8tDPICbfhy3RSa p6Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=jHM+XBmQ6ZTO6XPJIak8YtvTur1P6I0I8T4l/ZP+lVM=; b=Wc40MHcsiOxYa/zdzuawwiY9HzQ4NuHZ/vWIBToiXm6N6lR+2V3Dy/cmOyII0Bi4K1 kkcgurW83c00y5SIbaZW1xY6/13qyxKZ8d5WB5KAT8cgV12lDFnWZOrY2V9FzawCixih 8lSAe/6U3rIQSF6rZ6D5Ng8+yIqHfyLlHuGlYlmIS5iJNWJ8ZylMgVH7gKo+AkFZlzah QWa4sen4OCsGJIri6njax1vLXFyOgZvnY/c4kW1q39ykAohmmS8XYtwrxHRGRSzk46uW i+GlKpQt7Pe7VPQUi6MF0A0WA0wUgQ2/wJ+gnZivW1A2ynW3D3CUEdQSFL65QwdmscqM j9aQ== X-Gm-Message-State: ANhLgQ1v0LdM1JgfotCpHHAwSyBOtcOLluaQ0/wvmpxdFGx83Uay8/8x fd0ETH333z518zcB7lTRmoalBQ== X-Google-Smtp-Source: ADFU+vvT686MnPfKsDTtOjRP0DBZkxdHigp1TdpPpymg9zWDirygE/8xFxb0NnZyEjlCxamdulxABQ== X-Received: by 2002:ae9:efc8:: with SMTP id d191mr5745449qkg.1.1585675118688; Tue, 31 Mar 2020 10:18:38 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.95.18.252]) by smtp.gmail.com with ESMTPSA id s36sm14153622qtb.28.2020.03.31.10.18.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 10:18:38 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 13D723009FE; Tue, 31 Mar 2020 14:18:36 -0300 (-03) Date: Tue, 31 Mar 2020 14:18:36 -0300 From: Alvaro Herrera To: Kyotaro Horiguchi Cc: jgdr@dalibo.com, andres@anarazel.de, michael@paquier.xyz, sawada.mshk@gmail.com, peter.eisentraut@2ndquadrant.com, pgsql-hackers@lists.postgresql.org, thomas.munro@enterprisedb.com, sk@zsrv.org, michael.paquier@gmail.com Subject: Re: [HACKERS] Restricting maximum keep segments by repslots Message-ID: <20200331171836.GA7973@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200331150755.GA3858@alvherre.pgsql> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020-Mar-31, Alvaro Herrera wrote: > I'm not sure if I explained my proposal clearly. What if > XLogGetLastRemovedSegno returning zero means that every segment is > valid? We don't need to scan pg_xlog at all. I mean this: XLogSegNo FindOldestXLogFileSegNo(void) { XLogSegNo segno = XLogGetLastRemovedSegno(); /* this is the only special case we need to care about */ if (segno == 0) return some-value; return segno + 1; } ... and that point one can further note that a freshly initdb'd system (no file has been removed) has "1" as the first file. So when segno is 0, you can return 1 and all should be well. That means you can reduce the function to this: XLogSegNo FindOldestXLogFileSegNo(void) { return XLogGetLastRemovedSegno() + 1; } The tests still pass with this coding. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services