Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sHyuj-00Bwil-GO for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Jun 2024 04:51:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sHyug-00D7gR-Gu for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Jun 2024 04:51:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sHyue-00D7gI-Tt for pgsql-hackers@lists.postgresql.org; Fri, 14 Jun 2024 04:51:47 +0000 Received: from wfhigh6-smtp.messagingengine.com ([64.147.123.157]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sHyuX-001Zsp-SP for pgsql-hackers@lists.postgresql.org; Fri, 14 Jun 2024 04:51:44 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.west.internal (Postfix) with ESMTP id C6F3B1800131; Fri, 14 Jun 2024 00:51:34 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Fri, 14 Jun 2024 00:51:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1718340694; x=1718427094; bh=L1klqYNs/P qTAX3JJOHSUVKSHYBpKKjkn4x4OKDtGCc=; b=g2bIdXiNJqqyQGFM2fwsMWMKdc 7VLsIADw6e24B05CFd+G5jvIxiNp/qil14ridWNNRyr0nQSCZ6ABT8ughE/BG1P7 KCoLo8RpyTIEbBh5I6HFUDfytdXgTuexkdA4YZ6g+ILT/r1BWWltZ6kmFUH/IApU fifHW6ZzjTf2gfm6RbDPRlFMR2CEv6z0pNoYUoQiIulS8tBEFkjE9tZ/SM6N4Nob 2+E6yqj4aRmzeJ4W1sQts7owG8Qc7b42pfO/PpLnrCAggmCdzxAd3NoD+ycae8Z6 Z4wG7CC7Bguvu4jK0B1BlCrEkowgMEc7D0hxM28D7zl/vCncgNMkxwooh2Tg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1718340694; x=1718427094; bh=L1klqYNs/PqTAX3JJOHSUVKSHYBp KKjkn4x4OKDtGCc=; b=MGWrAEOxjxz11SpRWCDOH49JxJhsBOup16memymCYLQZ OGr0zs6FpP/hG0Vah3wlY6XmrC5mulr7Lq0lTcMM+3X7zohJdd2dpOjeZqeT6/2T EXxeIWdO2IXW7RDjLoFLhSIsX4Zt8wK/EBsv1OSj7BWTyXHH3RJPZo5vlXnCbdDJ 13HVmfIQrSpdQJ5ywilHg8YMbhQUyLVpkYE8b2aP0Be9OFL/JitfcYdK1ykfnVvS u2BCbPURId4tUVCpHEhE0FQV/gwe9f/b6JswNdgbQ8AlrpUB/9dJwfwHJiXOK8NJ TKuY3IBKGHpLBRhtSGQes1OvrbDK7xP4yTQQ+NIA+g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedukedgjeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdlfeehmdenucfjughrpeffhf fvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfrrghq uhhivghruceomhhitghhrggvlhesphgrqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvg hrnhepteelieefudffhffhtdetleeggeegfffhkeeuveetiefgudduvedutefggeeivdej necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhhitg hhrggvlhesphgrqhhuihgvrhdrgiihii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 14 Jun 2024 00:51:32 -0400 (EDT) Date: Fri, 14 Jun 2024 13:51:17 +0900 From: Michael Paquier To: m.litsarev@postgrespro.ru Cc: pgsql-hackers@lists.postgresql.org Subject: Re: SQL function which allows to distinguish a server being in point in time recovery mode and an ordinary replica Message-ID: References: <06c02ef916d85e77778e5cdfdf67a3df@postgrespro.ru> <4ba66566b84df983c881b996eb8831f1@postgrespro.ru> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="RpzOvGa20+1A3Wug" Content-Disposition: inline In-Reply-To: <4ba66566b84df983c881b996eb8831f1@postgrespro.ru> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --RpzOvGa20+1A3Wug Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jun 13, 2024 at 09:07:42PM +0300, m.litsarev@postgrespro.ru wrote: > Hi! >=20 > Michael, > I have fixed the patches according to your comments. >=20 > > merge both local variables into a single bits32 store? > This is done in v3-0001-Standby-mode-requested.patch >=20 > > Then this could be used with a function that returns a > > text[] array with all the states retrieved? > Placed this in the v3-0002-Text-array-sql-wrapper.patch >=20 > > The refactoring pieces and the function pieces should be split, for > > clarity. > Sure. I also added the third patch with some tests. Perhaps it would be > usefull. + * -- XLR_PROMOTE_IS_TRIGGERED indicates if a standby promotion + * has been triggered. Protected by info_lck. + * + * -- XLR_STANDBY_MODE_REQUESTED indicates if we're in a standb= y mode + * at start, while recovery mode is on. No info_lck protection. + * + * and can be extended in future. This comment is incorrect for XLR_STANDBY_MODE_REQUESTED? A startup we would unlikely be in standby mode, most likely in crash recovery, then switch to standby mode. - LocalPromoteIsTriggered =3D XLogRecoveryCtl->SharedPromoteIsTriggered; + LocalRecoveryDataFlags &=3D ~XLR_PROMOTE_IS_TRIGGERED; + LocalRecoveryDataFlags |=3D + (XLogRecoveryCtl->SharedRecoveryDataFlags & XLR_PROMOTE_IS_TRIGGER= ED) Are these complications really needed? All these flags are false, then switched to true. true -> false is not possible. StandbyModeRequested =3D true; ArchiveRecoveryRequested =3D true; + XLogRecoveryCtl->SharedRecoveryDataFlags |=3D XLR_STANDBY_MODE_REQ= UESTED; Shouldn't STANDBY_MODE be only used in the local flag, as well as an ARCHIVE_RECOVERY_REQUESTED? It looks like this could push a bit more forward the removal of more of these booleans, with a bit more work.. return (LocalRecoveryDataFlags & XLR_HOT_STANDBY_ACTIVE); } =20 + /* Some noise lying around. + /* Returns bit array as Datum */ + txt_arr =3D construct_array_builtin(flags, cnt, TEXTOID); Yep, that's the correct way to do it. +is($ret_mode_primary, '{}', "master is not a replica");=20 The test additions are welcome. Note that we avoid the word "master", see 229f8c219f8f. -- Michael --RpzOvGa20+1A3Wug Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmZrzEUACgkQnvQgOdby QH3Ipg/8DARdfDLhz/N3i2X1/5per6wC5bmnvGytmyB9PPENY78w5yMilTfdQ/pn eNfvZ2/rQQHF5739LoHZiVZTkMTBUqmtEE/yx+aHTWuytsA2ow2D4k6BLfFOKaT4 yI8zlZGuL0M26eftZKuovvoVCg1izzPWSJxf/3aiA6yf4xjMfuTy8kM42wCMVUO0 abgWSXiO8FEW1f7UVQlwn1nA7gTeHItZeLakn1VXNbhyuXme3/po2IeWY45dHsxr dFVLJQLuK+TaevF5GihhNCiWjHG9k7YRsv/2q1MkkNR5VJ+HPew4JAMjviVnoC2W 3YpbHDyPufcD+47CplSKGDB3tQS4odN8X8PQHp0maTHPFxUp7aNt0xVxI/LYqYDV EVBOXbtUGE/+vTXT+p+ijrv6xedwhXmVr+VSYEBf8Rnp2gxINF081/uSMIfWjchC nnZNwoNIUQJMP4Fh9yaQAZ/OqDXB40H0MY5I2acQYf2SVUwALuvlq9iMkxcELIQn THekSnGEz8TqbQMXQSS5X/nrYYpXN3X4nJY/5IPhL1fUxEuP7CEgQ70+DaHQIrOj VGUUrJhlEczH/1HL5BgXOWz9HhVmrcsfxedeP4dUQRe2mmrYL0Jy75QmB5o/NpZB xswNu02r3Te4gpDPBAqqNSRcBZXS5piH28ZxFgnFKzkeRo+Xmao= =6Oti -----END PGP SIGNATURE----- --RpzOvGa20+1A3Wug--