Re: Best Practices for Checking PostgreSQL Server Mode with Multiple Connections - Mailing list psycopg

From Adrian Klaver
Subject Re: Best Practices for Checking PostgreSQL Server Mode with Multiple Connections
Date
Msg-id 3f5dbc35-3578-4036-bbd4-94efdffe1718@aklaver.com
Whole thread Raw
In response to Re: Best Practices for Checking PostgreSQL Server Mode with Multiple Connections  (YoungUk Song <pidaoh@g.skku.edu>)
List psycopg
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 
> <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




psycopg by date:

Previous
From: Christophe Pettus
Date:
Subject: Re: Best Practices for Checking PostgreSQL Server Mode with Multiple Connections
Next
From: Vladimir Ryabtsev
Date:
Subject: Memory