psycopg2.pool.SimpleConnectionPool, Exception OperationalError takes time to be thrown

0

I did a test, shut down the server and called the psycopg2.pool.SimpleConnectionPool method, the method is waiting for a response for a very long time, about a minute, only then it raises the OperationalError exception. This is normal? Can you reduce the wait time?

>>>import psycopg2, psycopg2.pool
>>> a=psycopg2.pool.SimpleConnectionPool(1, 2, host = 'ip-do-server', user = 'postgres', password = 'postgres', database = 'nomebanco', port = 5432)
    
asked by anonymous 21.01.2016 / 20:36

1 answer

0

Use parameter connect_timeout in seconds:

psycopg2.pool.SimpleConnectionPool (
    1, 2,
    host = 'ip-do-server',
    user = 'postgres',
    password = 'postgres',
    database = 'nomebanco',
    port = 5432,
    connect_timeout = 15
)

The parameters of class SimpleConnectionPool are passed to function connect :

  

New minconn connections are created automatically. The pool will support a maximum of about maxconn connections. * args and ** kwargs are passed to the connect () function.

Which in turn refers to libpq:

  

The connection parameters can be specified either as a libpq connection string using the dsn parameter or using a set of keyword arguments

    
22.01.2016 / 14:56