The psycopg2 db connection with statement does not actually close the
database connection causing lots of idle postgres connections on the
production servers. An idle postgres connection can be found by doing
ps aux on the database servers, for example you will see something
like this:
"Note that, unlike file objects or other resources, exiting the
connection’s with block doesn't close the connection but only the
transaction associated with it"
This change creates a db_connect function that is like
psycopg2.connect but closes the db connection when exiting the with
block.
Coverage increased (+0.02%) to 97.148% when pulling ed9189687cc850664c97bd217b6b91e28abc0bca on close-db-connections into 0333632d0469bc0eca5cd56c1abad90b05e9b43f on master.
The psycopg2 db connection
with
statement does not actually close the database connection causing lots of idle postgres connections on the production servers. An idle postgres connection can be found by doingps aux
on the database servers, for example you will see something like this:On http://initd.org/psycopg/docs/usage.html#with-statement
"Note that, unlike file objects or other resources, exiting the connection’s with block doesn't close the connection but only the transaction associated with it"
This change creates a
db_connect
function that is likepsycopg2.connect
but closes the db connection when exiting thewith
block.