Django 1.6 now supports CONN_MAX_AGE
to pool database connections.
By default, the value is 0 (no pooling). What is a sensible value for this option?
They're controlled by the CONN_MAX_AGE parameter which defines the maximum lifetime of a connection. It can be set independently for each database. The default value is 0 , preserving the historical behavior of closing the database connection at the end of each request.
If you want to connect through TCP sockets, set HOST to 'localhost' or '127.0.0.1' ('host' lines in pg_hba.conf ).
By default, the configuration uses SQLite. If you're new to databases, or you're just interested in trying Django, this is the easiest choice. SQLite is included in Python, so you won't need to install anything else to support your database.
This value depends on the traffic of your site, the more traffic the more seconds to retain the connection, I'd recommend setting a relatively small value like 60
and tuning it accordingly to the usage pattern.
Edit (2018):
Like @jcyrss pointed out, this method has its quirks, for future reference I'd recommend handing out pooling to something like pgbouncer instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With