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 1jsdra-0000g1-0E for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jul 2020 03:01: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 1jsdrY-0002ed-TU for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Jul 2020 03:01:40 +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 1jsdrY-0002eW-Hp for pgsql-hackers@lists.postgresql.org; Tue, 07 Jul 2020 03:01:40 +0000 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jsdrW-00054G-3o for pgsql-hackers@lists.postgresql.org; Tue, 07 Jul 2020 03:01:39 +0000 Received: by mail-qk1-x743.google.com with SMTP id 145so34427976qke.9 for ; Mon, 06 Jul 2020 20:01:37 -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=80AgmWv3B1HYiWw+eAnGayLeqc1EZz1RejmAHEfA6G8=; b=lygY+Zq8cr59dk7f2HOHXrwtGrUsfPM9QgFAtQUsaxaOOXRfaBMt1+5BZz37hpX3Tl HE1XM/dpEDH+0RMHXr6kbvCg9RD/Q4pdCXUA7ZJeAiZDHCLZePuccI9E3qSvpDWUNNck kn3ibeu+4JlEKpY95Ut+Eh1ySW3CxTn+yfP96mj6bnN/7B/wjirDjoJW3zpV4Vgh8Qeg 5GU8ojq53rHdiK++YuwknvHnIxUYlBwQVAYrJ8ADX9xaZQPUUQifamdxemsXo+hMmeBL M5spc5DSWr29yU9+AGqp3Ue4RIASDjhq+QdqSGpudgtrYpcllf2cxHTtXSNqqFg1lZko kN6g== 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=80AgmWv3B1HYiWw+eAnGayLeqc1EZz1RejmAHEfA6G8=; b=Y1zFfdgfPdD+SYHSed5vpK17ayVXQAnPRe+e0khEuDaGqWqKEhf2VNMzpTf3lf8kmS aX656bgvyeTuHehdDN4pi098C7ljFoUgCXcLbX8imyVjR63nPDqqtQg8WmQ8gAlUu7fY Pu8I97CeQhz8tM3Zelvu95pN+LLr+749rC17VJ1ojur5mO6BGy9iOD31XRCC4z8nO1Op XdU81gzM3uzgr+Evww+IrZ41h0JelaiNsM1PX4ZofmFYG6vmwXrZMWZH9nWsBau8iZmv abHczF+ExE0UjAK/vS7AzVVflQyzv4aUMYY+J2ziuMYnZBblJOzCMyCJrn+CpY2Uc3wS Q9RA== X-Gm-Message-State: AOAM53167JaJhkK9lt61EqJS7bJ7agBPsWGXdfTccZ0xjoW6LkAJHcUJ lLG3bA0pAdf6ReNqGlZ/oB4ivQ== X-Google-Smtp-Source: ABdhPJzJrQRkHYgj6N3tJj6aIMbpYf/7GFZAWGgyyV4gJ/ogs7QB7J+Xp01QkH1Y1lU309n6hdLjug== X-Received: by 2002:a37:9a06:: with SMTP id c6mr52760215qke.161.1594090897110; Mon, 06 Jul 2020 20:01:37 -0700 (PDT) Received: from perhan.alvh.no-ip.org ([190.95.18.252]) by smtp.gmail.com with ESMTPSA id x26sm22413835qtr.4.2020.07.06.20.01.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2020 20:01:36 -0700 (PDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 01ED02A25B9; Mon, 6 Jul 2020 23:01:33 -0400 (-04) Date: Mon, 6 Jul 2020 23:01:33 -0400 From: Alvaro Herrera To: Kyotaro Horiguchi Cc: amit.kapila16@gmail.com, masao.fujii@oss.nttdata.com, michael@paquier.xyz, pgsql-hackers@lists.postgresql.org Subject: Re: min_safe_lsn column in pg_replication_slots view Message-ID: <20200707030133.GA29468@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200707.105510.1854619474409337397.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-Jul-07, Kyotaro Horiguchi wrote: > At Mon, 6 Jul 2020 20:54:36 -0400, Alvaro Herrera wrote in > > I propose the attached. This is pretty much what was proposed by > > Kyotaro, but I made a couple of changes. Most notably, I moved the > > calculation to the view code itself rather than creating a function in > > xlog.c, mostly because it seemed to me that the new function was > > creating an abstraction leakage without adding any value; also, if we > > add per-slot size limits later, it would get worse. > > I'm not sure that detailed WAL segment calculation fits slotfuncs.c > but I don't object to the change. However if we do that: > > + /* determine how many segments slots can be kept by slots ... */ > + keepSegs = max_slot_wal_keep_size_mb / (wal_segment_size / (1024 * 1024)); > > Couldn't we move ConvertToXSegs from xlog.c to xlog_ingernals.h and > use it intead of the bare expression? I was of two minds about that, and the only reason I didn't do it is that we'll need to give it a better name if we do it ... I'm open to suggestions. > > The other change was to report negative values when the slot becomes > > unreserved, rather than zero. It shows how much beyond safety your > > slots are getting, so it seems useful. Clamping at zero seems to serve > > no purpose. > > The reason for the clamping is the signedness of the values, or > integral promotion. However, I believe the calculation cannot go > beyond the range of signed long so the signedness conversion in the > patch looks fine. Yeah, I think the negative values are useful to see. I think if you ever get close to 2^62, you're in much more serious trouble anyway :-) But I don't deny that the math there could be subject of overflow issues. If you want to verify, please be my guest ... > > One thing that got my attention while going over this is that the error > > message we throw when making a slot invalid is not very helpful; it > > doesn't say what the current insertion LSN was at that point. Maybe we > > should add that? (As a separate patch, of couse.) > > It sounds helpful to me. (I remember that I sometime want to see > checkpoint LSNs in server log..) Hmm, ... let's do that for pg14! Thanks for looking, -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services