More information:

I tested by going into the python pod, and running looped psql select 1 
command with and without PGCONNECT_TIMEOUT=2.  Without the PGCONNECT, I 
also saw 2 minute delays but with PGCONNECT set, the error came back in 2 
secs.  I expected the same results by setting the connect_timeout but I 
don't see them.

Thanks

On Tuesday, 25 February 2020 21:11:56 UTC-8, Karim Gillani wrote:
>
> We are using openshift which uses HAProxy.  What I am looking for is why 
> the connect_timeout may not being applied so that we can retry the call 
> after re-connect to the other database pod.  
>
> It is taking *up to two minutes* before I get 
> the psycopg2.OperationalError.  It's very strange.  The code will 
> automatically retry and work after this error shows up.  I am guessing but 
> I don't think my setup is passing the connect_timeout to libpq.
>
> Thanks
>
> On Tuesday, 25 February 2020 10:37:19 UTC-8, Mike Bayer wrote:
>>
>> "could not connect" means your server is unreachable from a network 
>> standpoint.  You want to make sure the server is running and that it is 
>> routable over the network you are trying to connect from.
>>
>> in an HA scenario, depending on what software is in use and how it does 
>> switchover, there can be long network lags, such as if it is moving a VIP 
>> from one machine to another.  You'd want to be using a proxy server such as 
>> HAProxy or PGBouncer rather than relying upon changing network routing.
>>
>>
>>
>> On Tue, Feb 25, 2020, at 12:07 PM, Karim Gillani wrote:
>>
>> Please note I am using a Pool.  And some other connections seem to 
>> recover fine.  After two minutes I get this message and things start 
>> working again:
>>
>> ==> AE K:11oh392; T:1; E:(psycopg2.OperationalError) could not connect to 
>> server: Connection timed out> Is the server running on host 
>> "patroni-mastertheq" (172.50.46.180) and accepting> TCP/IP connections on 
>> port 5432?>>(Background on this error at: http://sqlalche.me/e/e3q8 ) 
>> Thanks
>> Karim
>>
>> On Tuesday, 25 February 2020 08:49:19 UTC-8, Karim Gillani wrote:
>>
>> I am having an issue where when my HA postgres database drops and is 
>> automatically moved to a backup database, the timeout doesn't seem to be 
>> working.
>>
>> My config.py shows the following:
>>
>> SQLALCHEMY_DATABASE_URI = 
>> '{engine}://{user}:{password}@{host}:{port}/{name}'.format(
>>
>> engine=DB_ENGINE,
>>
>> user=DB_USER,
>>
>> password=DB_PASSWORD,
>>
>> host=DB_HOST,
>>
>> port=DB_PORT,
>>
>> name=DB_NAME,
>>
>> )
>> SQLALCHEMY_ENGINE_OPTIONS
>> = { 'pool_size' : pool_size, 'max_overflow' : max_overflow, 
>> 'pool_pre_ping' : True, 'pool_timeout': DB_POOL_TIMEOUT, 'pool_recycle': 
>> 3600, 'connect_args': { 'connect_timeout': 5, 'options' : '-c 
>> statement_timeout=5000' } }    
>>
>> Is there something I set wrong?  My timeout seems to be about 2 minutes 
>> instead of 5 secs.
>>
>> Any help would be appreciated,
>>
>> Thanks
>> Karim
>>
>>
>> --
>> SQLAlchemy - 
>> The Python SQL Toolkit and Object Relational Mapper
>>  
>> http://www.sqlalchemy.org/
>>  
>> To post example code, please provide an MCVE: Minimal, Complete, and 
>> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
>> description.
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "sqlalchemy" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/sqlalchemy/ab3e5681-d9be-468f-8160-97bddcca57fb%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/sqlalchemy/ab3e5681-d9be-468f-8160-97bddcca57fb%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>>
>>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/778d34b5-463a-4561-8339-b72ec077cc62%40googlegroups.com.

Reply via email to