Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a good value for CONN_MAX_AGE in Django?

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?

like image 273
Brendan Nee Avatar asked Nov 12 '13 18:11

Brendan Nee


People also ask

What is Conn_max_age?

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.

What need to set in settings py to tell Django which host to use when connecting to database?

If you want to connect through TCP sockets, set HOST to 'localhost' or '127.0.0.1' ('host' lines in pg_hba.conf ).

Which is default database that come with Django?

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.


1 Answers

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.

like image 165
MGP Avatar answered Sep 21 '22 01:09

MGP