Skip to content

Pool doesn't keep connections open #563

@ibrewster

Description

@ibrewster

When using psycopg2 pool, specifically with the "close" parameter of putconn set to false, I was expecting behavior like the following:

  • create a "pool" of connections, with an initial number of connections equal to the "minconn" argument
  • When getconn is called, see if there is an available connection. If so, return it. If not, open a new connection and return that (up to "maxconn" total connections)
  • When putconn is called, return the connection to the pool for re-use, but do not close it (unless the close argument is specified as True, documentation says default is False)
  • On the next request to getconn, this connection is now available and so no new connection will be made
  • perhaps (or perhaps not), after some time, unused connections would be closed and purged from the pool to prevent large numbers of only used once connections from laying around.

However, in my testing, this does not appear to be the case - rather, every time I call putconn, the connection is closed unless that would result in fewer than minconn connections. Is this expected behavior, or is my expected behavior correct? If this is expected behavior, then what is the point of using pool? Just providing a hard limit for the number of allowed simultaneous connections?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions