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 1jv2By-00021K-R1 for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Jul 2020 17:24:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jv2Bx-0003xe-Mq for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Jul 2020 17:24:37 +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 1jv2BP-0005Ky-Az for pgsql-hackers@lists.postgresql.org; Mon, 13 Jul 2020 17:24:03 +0000 Received: from mail-qv1-xf43.google.com ([2607:f8b0:4864:20::f43]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jv2BN-0004X4-2B for pgsql-hackers@lists.postgresql.org; Mon, 13 Jul 2020 17:24:02 +0000 Received: by mail-qv1-xf43.google.com with SMTP id dm12so6126139qvb.9 for ; Mon, 13 Jul 2020 10:24: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=V/Zp6nLdSHHedPEdBm8164JlYD8H9VG1Afts4dRiCxc=; b=HzJfK+MmlyagTzTCd/Z5qqpX4A/qpEgBzQjuqWw8oWslTdld+DOBSZs7vsTFAhTTTH Me1tfdz2cU3Puh1oVgGAdCL5eToPKGvkyoKIDBgS3wwPR0/UUNgOJEpmBYNHOkor53I2 UU4gqZqmzIalOQf3/x/Ifd0ias3/jVP3Lmje5eo7WatZxXOUtL2HentViIrpIgekhHtC Fyreot+9h7m5gdzoHEnfweFXYXZaZMiJ4Pnh55S0BOyjGdP5n4K+UgE8M34eVjH2HGpU IWbJMYTypUpeHkUVxYy+ewunZVCYiLnvEI+rmKJbw0dyHSVX3jitkU+0BdE7RXZgJI6i LK3w== 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=V/Zp6nLdSHHedPEdBm8164JlYD8H9VG1Afts4dRiCxc=; b=cCKX4Y7/86l/nR1KXDqY62wlhT838YjSiVZAVx4xs/BPTqd7fuuMIY/PIzoRefCaMb xoTqSZ8GyoJ7Blo2Tt7oThK9IZwtAERCz5nn7E69lRPtGgELem53CiYz3fMYdk+lYhAD U8MgPQHVataY0R9ShEfhefSsq4HgCI4l5oMBldYYjZRNs0Uatmrd4/HfqoWVo10c+QWX tS4EQckD9Kp0tk/bziZHV8YT+4peO7jG4mapTnVdafbju0GH14ItSqDONFSQj5GucsdC hDhp+J+jIUcuPBmpkN7KAdfJdGviCWHDKWy+rJQ8HUlYtLMvt4iKHg+2udXuD0YBpIXT G0Ww== X-Gm-Message-State: AOAM532phSF0/1pdTyxXuW6KTZHQQ8/kqFUSKCmlke5CclQupEjVkYV9 krkEGGpLcmRtWwEvOOGVuqTgDQ== X-Google-Smtp-Source: ABdhPJxYR71xSBfZrDdIIJTyASBkpwpewng3J9oq/piuXMR9HqeNLoNMWW2M9G5VwgRDVSwttsU39g== X-Received: by 2002:a0c:e14d:: with SMTP id c13mr522194qvl.158.1594661040014; Mon, 13 Jul 2020 10:24:00 -0700 (PDT) Received: from perhan.alvh.no-ip.org ([190.95.19.47]) by smtp.gmail.com with ESMTPSA id k194sm19265662qke.100.2020.07.13.10.23.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2020 10:23:58 -0700 (PDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id AA4722A18A9; Mon, 13 Jul 2020 13:23:56 -0400 (-04) Date: Mon, 13 Jul 2020 13:23:56 -0400 From: Alvaro Herrera To: Tom Lane Cc: pgbf@twiska.com, Kyotaro Horiguchi , masao.fujii@oss.nttdata.com, pgsql-hackers@lists.postgresql.org Subject: Re: min_safe_lsn column in pg_replication_slots view Message-ID: <20200713172356.GA446@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="pWyiEgJYm5f9v55/" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200711212630.GA6825@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 --pWyiEgJYm5f9v55/ Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit A much more sensible answer is to initialize the segno to the segment currently being written, as in the attached. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --pWyiEgJYm5f9v55/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0001-Fix-uninitialized-value-in-segno-calculation.patch" From 699e3a25e0673353fcb10fa92577f7534e594227 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Mon, 13 Jul 2020 13:22:40 -0400 Subject: [PATCH v3] Fix uninitialized value in segno calculation Remove previous hack in KeepLogSeg that added a case to deal with a (badly represented) invalid segment number; to replace it, initialize the segment number to be retreated to the currently being written segment. Per valgrind-running buildfarm member skink, and some sparc64 animals. Discussion: https://postgr.es/m/1724648.1594230917@sss.pgh.pa.us --- src/backend/access/transam/xlog.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 28daf72a50..0a97b1d37f 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -9523,13 +9523,13 @@ GetWALAvailability(XLogRecPtr targetLSN) if (XLogRecPtrIsInvalid(targetLSN)) return WALAVAIL_INVALID_LSN; - currpos = GetXLogWriteRecPtr(); - /* - * calculate the oldest segment currently reserved by all slots, - * considering wal_keep_segments and max_slot_wal_keep_size + * Calculate the oldest segment currently reserved by all slots, + * considering wal_keep_segments and max_slot_wal_keep_size. Initialize + * oldestSlotSeg to the current segment. */ - XLByteToSeg(targetLSN, targetSeg, wal_segment_size); + currpos = GetXLogWriteRecPtr(); + XLByteToSeg(currpos, oldestSlotSeg, wal_segment_size); KeepLogSeg(currpos, &oldestSlotSeg); /* @@ -9548,6 +9548,9 @@ GetWALAvailability(XLogRecPtr targetLSN) else oldestSegMaxWalSize = 1; + /* the segment we care about */ + XLByteToSeg(targetLSN, targetSeg, wal_segment_size); + /* * No point in returning reserved or extended status values if the * targetSeg is known to be lost. @@ -9624,7 +9627,7 @@ KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo) } /* don't delete WAL segments newer than the calculated segment */ - if (XLogRecPtrIsInvalid(*logSegNo) || segno < *logSegNo) + if (segno < *logSegNo) *logSegNo = segno; } -- 2.20.1 --pWyiEgJYm5f9v55/--