How to handle disconnect on connection pools

From: Diego Pasqualin <dpasqualin(at)c3sl(dot)ufpr(dot)br>
To: psycopg(at)postgresql(dot)org
Subject: How to handle disconnect on connection pools
Date: 2015-01-23 17:36:24
Message-ID: CADpKL+1=1KsZ1CeuPdmWkoKJ1c2DeVi2Nm_B+mrQiQ-GgNUwdQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: psycopg

Hi,

I have an application with many threads using a PersistentConnectionPool.
It works great, until someone restarts the database, disconnecting all
connections in the pool.

So, what can I do to recover the connections when the server restart?

I was thinking about catching psycopg2.OperationalError in a try/except
statement, executing a pool.putconn(conn, close=True) to close the
problematic connection, then trying to execute the SQL query again. Though,
I'm not sure if the PersistentConnectionPool class would create a new
connection afterwards, or if this is the right way to do it...

Thanks,

--
Diego G. Pasqualin
UFPR - Universidade Federal do Paraná
C3SL - Centro de Computação Científica e Software Livre

Responses

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2015-01-23 18:08:05 Re: How to handle disconnect on connection pools
Previous Message W. Matthew Wilson 2015-01-23 15:39:46 Re: Can't register python class for domain?