I'm using Django 1.10 and PostgreSQL DB.
I'm trying to figure out whether I can set statement_timeout
from Django.
Seems like I can't do it the same way as for connect_timeout
(in settings.py
):
DATABASES[DEFAULT]['OPTIONS'] = {
'connect_timeout': float(os.getenv('DEFAULT_DB_OPTIONS_TIMEOUT', 5))
}
I saw something like this, but I can't find a way to verify it actually works:
DATABASES[DEFAULT]['OPTIONS'] = {
'options': '-d statement_timeout=700'
}
I know I can set it directly from the DB like:
set statement_timeout=5000
but I'm looking for a way to do it from Django.
There is no other "Django" way of doing this. The Django way is to use your settings.py
like you indicate, except your example is not quite right. It should be:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
...
'OPTIONS': {
'options': '-c statement_timeout=5000',
...
}
}
}
The 'OPTIONS' dictionary is for arguments to the database connection string. The list of Postgres arguments can be found here. The options
connection string argument allows you to specify command-line arguments for postgres. The -c
option is explained here.
Note that the timeout is measured in milliseconds, so the 5000
above means 5 seconds.
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