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 1iGiSu-0008Hc-KR for pgsql-bugs@arkaria.postgresql.org; Sat, 05 Oct 2019 11:43:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iGiSt-0002kL-CC for pgsql-bugs@arkaria.postgresql.org; Sat, 05 Oct 2019 11:43:11 +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 1iGiSs-0002k3-TR for pgsql-bugs@lists.postgresql.org; Sat, 05 Oct 2019 11:43:11 +0000 Received: from mail-ua1-x92e.google.com ([2607:f8b0:4864:20::92e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iGiSq-0005fp-9y for pgsql-bugs@lists.postgresql.org; Sat, 05 Oct 2019 11:43:09 +0000 Received: by mail-ua1-x92e.google.com with SMTP id k24so2799924uag.10 for ; Sat, 05 Oct 2019 04:43:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=to:from:subject:autocrypt:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=50pfrcTZPzsKnP36WnjYgSlEhRmIo2CcLv2tH60cGhU=; b=u2utxny42oAEg1G9ZsmpXHxovw4+TJmAMKRFHNa5JwLDOLRB6LMibm4ZA2S/mT792m CqjZTNPfps+RhHC5DT7LEKz7W8u8wYAPyg7tcNgRmnCVQ+IhHpsvlan5DvBdziAYWm8I tG9kHGFd017aTfC+E77pZCJYuLXjaKOUMSC6XD/dtLj1qwx99pYVqhgGLhdkMFvkm9NZ l6ZpVocOfyjz5NATV004yOV48R7DpVYZtJFRcVJ7ERacgXliHeYtLcCCRU/bC5hbqVSL K/VC2c50x/EIXddPN4tSKEMGbq68iqUp4144X6FQlr3QLxeyiScVWgpbZRx/2Sp6F5Ib fOBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:autocrypt:message-id:date :user-agent:mime-version:content-language:content-transfer-encoding; bh=50pfrcTZPzsKnP36WnjYgSlEhRmIo2CcLv2tH60cGhU=; b=pHhI9NiA4qXBpRpv1ai2ewJNgGeUd+SluntEQz+HEYtH3+DXe4RMKCdTMbmgVi83ja Te/zVuaagxp59q4p+6cjhokwOjKoJyFSv8duMK1bND+es1ajjMDk/iOuDEldGTqN8lw4 BcrwVdxbHwj7vWRMHxr7GX3YgB5qHUNQiq8WOxw8yxeUPnsjf6ywpbD/SAqwPN6vjm09 7/l2GKG22IUkoHHl91OcJEP7+X60yTVjuL1LOz4uUqovzRYSWs9DasuidC9PYXM+q+Ic tAfzPSzD6PDmoi4V10mISnQIyQh2l/yDUMadqi/xNIRnbZAJJH0mLsRBp18yXmby4peG 4i1A== X-Gm-Message-State: APjAAAUrg5vrzSBxHxz22HDms/uIFvqKyFPCgljT9NYe9PIOweFWO0/B 9AGwztyY05yc2/O8RYz07LyjuA== X-Google-Smtp-Source: APXvYqz5Q8QzDcIJwNyQ6fWkv+0gFupsmNNqcFGeRTbuqQfrzwMH1W5GYvvza8e3gPdte92JwUq9JA== X-Received: by 2002:a9f:24c4:: with SMTP id 62mr10496214uar.104.1570275786892; Sat, 05 Oct 2019 04:43:06 -0700 (PDT) Received: from hoth.marques ([170.51.176.135]) by smtp.googlemail.com with ESMTPSA id k188sm1815832vsk.6.2019.10.05.04.43.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 05 Oct 2019 04:43:06 -0700 (PDT) To: pgsql-bugs@lists.postgresql.org, PostgreSQL-development From: =?UTF-8?Q?Mart=c3=adn_Marqu=c3=a9s?= Subject: Non-null values of recovery functions after promote or crash of primary Autocrypt: addr=martin@2ndquadrant.com; prefer-encrypt=mutual; keydata= mQENBFGQ9akBCAC+rCultjweJUjKgFfj0s3XQULnyNrC3N8C7Y2v5xPEw+EZAD6+kVDimItf jY2oZGdP8+dmfr79zVSx7IBN+BPXiz+8k+DnGrHchIrGoVcXbOomqqKBYDQYA1DvGU4Nfu3+ g7Iu3FFRdOuJkhW6mP+uXLs3VudM36Ksu9nnWSAtZ7+1k4klstwQEIJk+8xDIi2azJnLstY7 mPOEG2jOIhC0w2Wl6BWIQi0pJr/EjfZRgta4ZrbHnROJZubRcdaZxZmT1bWjrAdPRo3taJzm A82hIh4gTkaFRmiyDvMu8Iu1k1dw1bA4ranrs1MwBbnXZFjLpjXrtc82+btU7yQN4Kb9ABEB AAG0OU1hcnTDrW4gTWFycXXDqXMgKERCQSBBcmdlbnRpbmEpIDxtYXJ0aW5AMm5kcXVhZHJh bnQuY29tPokBPgQTAQIAKAIbAwYLCQgHAwIGFQgCCQoLBBYCAwECHgECF4AFAlsCpfUFCQ00 FzQACgkQewO0SAEAVNKFygf+O2tIEXklaoSUhx2XM62NX7Ao8VaTaVBFZv1PFyKjqK96NZL6 oGjqO9z7LXjIWUatXVBH3Cxa4j/RNovWh0eNykIHZQN/gAYNB9eE8TmRRtj+S3D/rukwnu2s 16ALzEu5x2OABFEgj+/hH3JFViSC1mBnibFLYtTm4ydzL/URpObffgCeHXxBrHZ0o7XZsTBk 8UwNcsFpblSEdEpCZj/14UwAlEs5DPEMqn0I0hNHcVbliPKhy7CETJSet0hbpJvFqaJTbb0d p6i/Z8bHP0IrmYJWpkX5vH9oexYyPRM+nc1FXJnich3MtHfA/fTtGrM9XLWCt+NX5pdkHIUE ApfLXLkBDQRRkPWpAQgAoNxnsp7AIiOBT8ufUbTGFWNbOsViwFT7kMnQixNaR69S/YBxkWit BdogJA9D0y0j/qBEzY+XwZGVPLi4eYYRl0+u6qobpmgy2fIGaIyW8H20Zi8RYcjbixfLNrZV W0Wj4RDgiv1wnJqlTTu6sNtv1pHXfxnTxB27DHbQnNiBt/NC4gvy3TRIEzAECOg+unFtOxhS jx6uNRllU/uo7iPYUyJT5HyTNxYQQRK3h6wGhtMlxPi+0mY7TvsS0Pmvi5wWPQRRRs+waYbX A7lYXO1a1SCeR4KgTm3AXcj0iTPL7xxsMZQuPIaJMf/p9x4Ay4M9V6Mn02AvA6TQezL7NVsO gwARAQABiQElBBgBAgAPAhsMBQJbAqZ8BQkNNBfPAAoJEHsDtEgBAFTSItoH/2l15R9tmcRv zuNpsoYxpI2u+hvItRiXTN0Q5cOiiR7t03I1LjqSu66DhpvNCpWcQ05KUyrUH6S/GrDHHkbX 461XwdTjJDjQB8DiKmLRduf/CLD9uhpKDocGiazN0rJrLwDIok73YjCBiOV5CRmEyCoK1mNW suMNC6sMjNdBUi2ZOFAcrvG+RotsjDDGc0fRAV9UhykJuZuiE+no6f/WDu/iV2bAU832+/m1 5Nh06IDKazVMw/Twfkxm1NTTL6W/wcQIk0LjAFSDzgYud0i0lbe67R+Al94n+Zfp5slgsB4u xGH9NyG1PkFOSA8WyXSEWXbLPgXmZh/E6FqefUbHnjA= Message-ID: <576b29e5-5edf-b4b7-bb73-7ffad63535e2@2ndquadrant.com> Date: Sat, 5 Oct 2019 08:43:03 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.0 MIME-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, Yesterday we (that's me and my colleague Ricardo Gomez) were working on an issue where a monitoring script was returning increasing lag information on a primary instead of a NULL value. The query used involved the following functions (the function was amended to work-around the issue I'm reporting here): pg_last_wal_receive_lsn() pg_last_wal_replay_lsn() pg_last_xact_replay_timestamp() Under normal circumstances we would expect to receive NULLs from all three functions on a primary node, and code comments back up my thoughts. The problem is, what if the node is a standby which was promoted without restarting, or that had to perform crash recovery? So during the time it's recovering the values in ` XLogCtl` are updated with recovery information, and once the recovery finishes, due to crash recovery reaching a consistent state, or a promotion of a standby happening, those values are not reset to startup defaults. That's when you start seeing non-null values returned by `pg_last_wal_replay_lsn()`and `pg_last_xact_replay_timestamp()`. Now, I don't know if we should call this a bug, or an undocumented anomaly. We could fix the bug by resetting the values from ` XLogCtl` after finishing recovery, or document that we might see non-NULL values in certain cases. Regards, -- Martín Marqués http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services