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 1jJIUm-0003VN-Dx for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2020 15:08:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jJIUl-0007lJ-AX for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2020 15:08:03 +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 1jJIUk-0007l0-Sr for pgsql-hackers@lists.postgresql.org; Tue, 31 Mar 2020 15:08:03 +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 1jJIUi-0001zW-IY for pgsql-hackers@lists.postgresql.org; Tue, 31 Mar 2020 15:08:01 +0000 Received: by mail-qk1-x744.google.com with SMTP id k13so23350678qki.2 for ; Tue, 31 Mar 2020 08:08:00 -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=uycCTGwq1BK+jXMeQCWkQpwMTX3VYrSeNOuvUKoQhzc=; b=My/BTqbzxl0qBs/tzm0vL2Bk5QN0V6L5rHD0SfMGWiLLsvWB8YK9ViY0sfuHKWtDKv hSu1+uRuOZ5H4TMnOPMKlvgmxb33lBw14EAG4b1tw+rVJA9Q2BFcAaVx4vRg9C1+KAAf d2tFlNeoUsljVIv5EfQm3osX46EGVo/grbgNkEHY69chFgrIRp27ArkhywlfUOjzYUJS EHAW9lfUiAOX/2LfUfdWoU0Rpu2tWrPNET3rDdhvfDKlnZ4WOC6o2wICGJ21blynZkXt EWC2mupk1MKVswHrXGDngbF5yiF7XHjEzK8gwl4cPIb0aSOagaH1GKMjbTo0FsWbUXF8 8lPg== 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=uycCTGwq1BK+jXMeQCWkQpwMTX3VYrSeNOuvUKoQhzc=; b=aV50nPNvnBWiBfkNaJsFEgp5Ym0Wfygwc6JEkkuJWmbceN+b6Sta7eFdejsfM3+vCP eIkSjfIYpM2oM7eLUAS61thx9r5iA2rBbjgLiWolD/gYgP4l4arJ7KOtnVH57DQAfpPp GMZCJ6g7xmQdRb6vT51yDLc/R3j9YGEM8PVQ6jxgfYlQhXu+BL5pyzaY98gHzGzCmXIq 6UdSGj9WLaWJPJfUmN8Sx0inAtQ5ScrkP5MHSEBo5ASaSEpSJOJ5Dp4Lvbff1mRXmvVC z6LynVwjjI7CafVUjOg9nv2OnfhPDP2i5I3TGpwCGKMo2ReyVAala0KouNPl3PwGGf5P hgjA== X-Gm-Message-State: ANhLgQ3JsJneBmfXfz/5CqPA6DN8bW5+NFYVfElvk+2wU9evyW3KyU5D QQXwkWc5Mm8lpMjRFx1OADlbCw== X-Google-Smtp-Source: ADFU+vuO0RTP9f8qgbuvw14zPNvcigKBiQY8HJA+V6ZzzJC5nQx2WWXs9XAn3lB8zCT/OQFjmla63w== X-Received: by 2002:a37:7ec6:: with SMTP id z189mr5410440qkc.162.1585667278037; Tue, 31 Mar 2020 08:07:58 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.95.18.252]) by smtp.gmail.com with ESMTPSA id c8sm13260088qke.90.2020.03.31.08.07.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 08:07:57 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 164CF3009FE; Tue, 31 Mar 2020 12:07:55 -0300 (-03) Date: Tue, 31 Mar 2020 12:07:55 -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: <20200331150755.GA3858@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200331.142016.971756479150607227.horikyota.ntt@gmail.com> 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, Kyotaro Horiguchi wrote: > Thank you for looking this and trouble rebasing! > > At Mon, 30 Mar 2020 20:03:27 -0300, Alvaro Herrera wrote in > > I rebased this patch; it's failing to apply due to minor concurrent > > changes in PostgresNode.pm. I squashed the patches in a series that > > made the most sense to me. > > > > I have a question about static variable lastFoundOldestSeg in > > FindOldestXLogFileSegNo. It may be set the first time the function > > runs; if it is, the function never again does anything, it just returns > > that value. In other words, the static value is never reset; it never > > advances either. Isn't that strange? I think the coding is to assume > > that XLogCtl->lastRemovedSegNo will always be set, so its code will > > almost never run ... except when the very first wal file has not been > > removed yet. This seems weird and pointless. Maybe we should think > > about this differently -- example: if XLogGetLastRemovedSegno returns > > zero, then the oldest file is the zeroth one. In what cases this is > > wrong? Maybe we should fix those. > > That's right, but without the static variable, every call to the > pg_replication_slots view before the fist checkpoint causes scanning > pg_xlog. XLogCtl->lastRemovedSegNo advances only at a checkpoint, so > it is actually right that the return value from > FindOldestXLogFileSegNo doesn't change until the first checkpoint. > > Also we could set XLogCtl->lastRemovedSegNo at startup, but the > scanning on pg_xlog is useless in most cases. > > I avoided to update the XLogCtl->lastRemovedSegNo directlry, but the > third way would be if XLogGetLastRemovedSegno() returned 0, then set > XLogCtl->lastRemovedSegNo by scanning the WAL directory. The attached > takes this way. 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. > > Regarding the PostgresNode change in 0001, I think adding a special > > parameter for primary_slot_name is limited. I'd like to change the > > definition so that anything that you give as a parameter that's not one > > of the recognized keywords (has_streaming, etc) is tested to see if it's > > a GUC; and if it is, then put it in postgresql.conf. This would have to > > apply both to PostgresNode::init() as well as > > PostgresNode::init_from_backup(), obviously, since it would make no > > sense for the APIs to diverge on this point. So you'd be able to do > > $node->init_from_backup(allow_streaming => 1, work_mem => "4MB"); > > without having to add code to init_from_backup to handle work_mem > > specifically. This could be done by having a Perl hash with all the GUC > > names, that we could read lazily from "postmaster --describe-config" the > > first time we see an unrecognized keyword as an option to init() / > > init_from_backup(). > > Done that way. We could exclude "known" parameters by explicitly > delete the key at reading it, but I choosed to enumerate the known > keywords. Although it can be used widely but actually I changed only > 018_repslot_limit.pl to use the feature. Hmm. I like this idea in general, but I'm not sure I want to introduce it in this form right away. For the time being I realized while waking up this morning we can just use $node->append_conf() in the 018_replslot_limit.pl file, like every other place that needs a special config. There's no need to change the test infrastructure for this. I'll go through this again. Many thanks, -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services