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 1tKh0j-00AEqF-JW for psycopg@arkaria.postgresql.org; Mon, 09 Dec 2024 16:53:29 +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 1tKh0h-00AGD0-0M for psycopg@arkaria.postgresql.org; Mon, 09 Dec 2024 16:53:28 +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 1tKh0g-00AGCq-Pb for psycopg@lists.postgresql.org; Mon, 09 Dec 2024 16:53:28 +0000 Received: from fhigh-a5-smtp.messagingengine.com ([103.168.172.156]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tKh0e-001v5j-Ka for psycopg@postgresql.org; Mon, 09 Dec 2024 16:53:27 +0000 Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfhigh.phl.internal (Postfix) with ESMTP id 90C7611401A4; Mon, 9 Dec 2024 11:53:23 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Mon, 09 Dec 2024 11:53:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding: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=fm3; t=1733763203; x=1733849603; bh=4G/eI2SP287L+AEk3PsDslPYpYHvZMV3vDvH9k1W3GQ=; b= k9EoGgDzmFjBfBUdDbS2rKW8qJaRQytcTQdK2ONJXUWpgMl/yUs5Zlq0JGPUD3O+ Rt75PFtOILAtyWnklkKhNKBXi6wr8tHD6valbgs93ArQGsq7wQPul9rgnQ9WnE7q MbwNeZEHN1dPnDZpIusqxBkqgwuEBTn95eEQA1lVDsaLp7vRlKMgiiz+hwOETfhz yoDwCAJl5+GhkU2ZVDSdj0yQDUt0imeVwK/bL2pZTs46J8J+YQ5MUa7gu6PmnL4f IQZshcGMm07pgXBvAQOWS9ek28M42Z4SvPkHmISOOlNsoyWXVgHxQ2sS+7BWWfTV 7ebfBKPHLNclQAWkNrq/Zg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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-sender :x-me-sender:x-sasl-enc; s=fm1; t=1733763203; x=1733849603; bh=4 G/eI2SP287L+AEk3PsDslPYpYHvZMV3vDvH9k1W3GQ=; b=RQNI7LraeOmNEdHi4 qxv6tKarn5uPUV7RaeBfRQM+Ia4IgL1sPdqE8Ruj0SrfT+bMP99qtWh3Ux+WHBBj jw72GO2++dV1dGHWPKi5vZpMUA8jOVdB5131GctIFSMxnnhVz/bINTSk6uyCZpRl lZuXe5h/RgiihrchyJBGxvzdfcqXTyO+oaIjhp0o6AMHAYv7fRGSh17tiD1XW09l qFflxliIy9Rjr0vtgvcqL76xV7zlwt8zw7H8pbXIitOWf1EKcS8vZ1nflVvSsX54 oy4p8X5XLOP9xv3iYy5Tikxw/vQn0AwVtEmlX2G+5uyHUs6q4drxGD5beSa96hvq SFmDw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrjeeigdeijecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuf fvfhfhjggtgfesthejredttddvjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcu oegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucggtffrrghtth gvrhhnpeelteegffehhfdtveelkeelffdtgfejleeiteduhfehhfetteetteetlefgtdev hfenucffohhmrghinhepphhshigtohhpghdrohhrghenucevlhhushhtvghrufhiiigvpe dtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhl rghvvghrrdgtohhmpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprh gtphhtthhopehpihgurghohhesghdrshhkkhhurdgvughupdhrtghpthhtohepphhshigt ohhpghesphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 9 Dec 2024 11:53:22 -0500 (EST) Message-ID: <3f5dbc35-3578-4036-bbd4-94efdffe1718@aklaver.com> Date: Mon, 9 Dec 2024 08:53:21 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Best Practices for Checking PostgreSQL Server Mode with Multiple Connections To: YoungUk Song , psycopg@postgresql.org References: <5ed40ad0-5012-48fa-b5c0-61abf7713080@aklaver.com> Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/9/24 06:04, YoungUk Song wrote: > Thank you for your response! > > I apologize for the confusion in my earlier message. > > I need to check whether more than 500 different database servers (not > just one) are operating in read-only or read-write mode using Psycopg. > > Are there any best practices for efficiently handling this task across > such a large number of servers? It is a matter of looping over a set of connection settings and recording the results. To me that points at a Postgres table with the connections settings and another table that tracks the results of the connection attempts. Then it is a matter of writing code that uses psycopg to make connections using the connection data on whatever schedule you want to follow. The results of the connection are then written out to the status table. Where results can be 1) Successful connection and server mode. 2) Unsuccessful connection and connection error. > > Can this be achieved using Psycopg's error-handling features, as > described here: https://www.psycopg.org/psycopg3/docs/api/errors.html > ? Yes use try/except for the connection attempts and capture the error if there is one. > > > Thanks! > -- Adrian Klaver adrian.klaver@aklaver.com