Articles from January 2021

« Back to 2021

Designing a connection pool for psycopg3

Posted by Daniele Varrazzo on 2021-01-17
Tagged as psycopg3, development

The psycopg2 pool is a pretty simple object, little more than... a pool of open connections, and I think it falls short in several ways:

  • the top usability problem is the fact that it cannot be used as context manager;
  • if a connection is broken it is not noticed it until it is used by a client;
  • if minconn connections are already taken, a new one is created and disposed of as soon as finished using, regardless of whether other clients may need it;
  • if more than maxconn connections are requested the client will receive an error.

For psycopg3 I would like something better. I have read around, looking into other pool implementations to figure out what a well designed connection pool ought to do (a very well thought one seems the Java HikariCP) and these are a few ideas I'd like to work on: they are here for a feedback, before I jump into enthusiastically implementing the wrong thing...