David Fraser
davidf at sjsoft.com
Fri Feb 13 08:46:34 EST 2004
ntimm wrote: > I am running mod python 3.0.4 with apache 2.0.47 connecting to a > postgresql database. The only issue I am having is that each time a > mod python script is called that has a db query in all just select > statements if leaves a instance of postgres running and eventually my > max connection to postgres is hit. I have tried the db.close > statements but then that cause sporadic errors with the connection not > being valid. The only way I have found to close the postgres instance > is either restart apache or postgres. I there some mod python variable > that I can use or any type of connection pooling Or maybe a apache > config option I have tried messing with the apache config but with no > luck. > > I have tried to use PythonImport variable but couldn’t get it to work > with the pg module at all. > > Any help would be appreciated. > > Thanks, > If you post some of the relevant code it will be easier to see what the problem is... But basically if you import the pg module, it will not be re-imported for each call. So you want to set up a global variable that is the connection, then just create a new cursor each time the script is run, and close the cursor at the end. Running under Unix, you will still get multiple connections because there are multiple Python Interpreters - one for each Apache process - but there will be a limit. Not sure about the connection pooling, but have a look at http://sqlrelay.sourceforge.net/ - I haven't used it, but it seems to be the kind of thing you want... David
|