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 1kg3FL-0003pI-7J for pgsql-general@arkaria.postgresql.org; Fri, 20 Nov 2020 10:02:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kg3FK-0000uf-7U for pgsql-general@arkaria.postgresql.org; Fri, 20 Nov 2020 10:02:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kg3FJ-0000uY-TX for pgsql-general@lists.postgresql.org; Fri, 20 Nov 2020 10:02:25 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kg3FF-0003FE-Vq for pgsql-general@lists.postgresql.org; Fri, 20 Nov 2020 10:02:25 +0000 Received: by mail-wr1-x434.google.com with SMTP id s8so9372024wrw.10 for ; Fri, 20 Nov 2020 02:02:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=uWbd58MInV7OmQ2aEPPlEYb++yJY4AuMVZNx3b4nLMA=; b=GaP9bj4/A0W7P5hufW61rPF1LuefPtVbsYsUlpP3fiICVc10lY6OOWHnwuWNupNLpd 1l86GrdoocALI2P1IUxmpiV2hCOudXZZLZVNTq8VCXdYDHm4GgCQQHGhoTKnxJYccK5l XsJYHCM0W4s9ZszdluEPf1VEJRRS7ogwn0ujcAwVLnh8LFsHvX3ekYOoQyggL4j4NjAT ++U7s7A0NU0wrcXHlji9rzgVGA+/7G2CzzxLpT8q0mXJeld9pdWZThb8ObKThF1AuBmm Fnsrz1nFDE2xPy/GuYjKszCYRrNpP9cPuTwbBTg+dycFm4+bngiIFKsyLEbGFrirKUgr aJwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=uWbd58MInV7OmQ2aEPPlEYb++yJY4AuMVZNx3b4nLMA=; b=mTQWTRrzGRh0hAqWO95hZ4hd2LvtNlLben5U9ciO6nHgvKUHs9Ux+qKlaQ66Rwsjba huuUqNPKrmaWKKHdaZ5XxC3F5JVyEPUtA+2mKEpOFYVDG5C7e8krog9k9BEiCsV1Lrg9 IWmodnfC56jkR/X3RYcUVHNPEoR3ilCaA6J1Fw8nVBrSUC8v/rKBVW62yKgJSw/c8g8E 0fqdUpIDCLDvIObF7qSD1SxzP6o44u/4KNjn6qdKGozbnRyHhCWU01O9TBk3iIVQjeW0 8e7+Jj3o2yF1OrsV1ql27DfIThmsHi4IWYxA8ikoUECMqoZ91pfO8991vhf/urZh55iv JHKA== X-Gm-Message-State: AOAM533PiYRU8vK4TQGhlFW2kbMAtRstM1l1ekIJAj9Q5nC6zNvH4Y8m Q6MY33WZDshF7II80H7c0OE= X-Google-Smtp-Source: ABdhPJwNFRIlMycBz7xi4H0Wx7ugGgKqUCH3e0yvFH5Oe1c9IIgWtwPNLNM4iKcMr7nBPfOCYUoDBQ== X-Received: by 2002:a5d:5482:: with SMTP id h2mr15361595wrv.18.1605866541278; Fri, 20 Nov 2020 02:02:21 -0800 (PST) Received: from [192.168.1.8] (241-57-239-77.dyn.cable.fcom.ch. [77.239.57.241]) by smtp.gmail.com with ESMTPSA id q2sm4431519wru.76.2020.11.20.02.02.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Nov 2020 02:02:20 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.20.0.2.21\)) Subject: Re: Determine if postgresql cluster running is primary or not From: =?utf-8?Q?Paul_F=C3=B6rster?= In-Reply-To: Date: Fri, 20 Nov 2020 11:02:20 +0100 Cc: Thomas Kellerer , "pgsql-general@lists.postgresql.org" Content-Transfer-Encoding: quoted-printable Message-Id: <7D1914CE-4A9C-4A3B-91D2-22954ACC2452@gmail.com> References: To: "David G. Johnston" X-Mailer: Apple Mail (2.3654.20.0.2.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi David, > On 20. Nov, 2020, at 10:34, David G. Johnston = wrote: >=20 >=20 > On Friday, November 20, 2020, Paul F=C3=B6rster = wrote: >=20 > > On 20. Nov, 2020, at 10:03, Thomas Kellerer wrote: >=20 > >=20 > > select pg_is_in_recovery(); >=20 > I usually don't recommend using pg_is_in_recovery() only because a = database cluster can be in recovery for other reasons. This is why I = always do the following: >=20 > Do any of those other reasons allow connections that could execute = that function to exist? that always depends on what your application does. An application could = still select a lot of things, maybe even wrongly so, even if the cluster = is in recovery mode. That was my idea when writing this query and it's been working fine for = years now. Cheers, Paul=