[Answered ]-Database performance in Django/Postgres

1👍

Hello I won’t answer your question straight away but since you suspect that the query is not slow you can rule it out.

  1. Enable query logging using the following config in your project’s settings.py LOGGING configuration:
        'django.db.backends': {
            'level': 'DEBUG',
            'handlers': ['console'],
            'propagate': False
        }

resource:
https://docs.djangoproject.com/en/3.1/topics/logging/#django-db-backends

this will log each query executed and the time it takes

  1. Another option is to enable a slow query log on your database but the above is simpler.

  2. If it appears that some query is slow you can get further details by copying the query and analysing the cost and the operations happening using buildin query plan analysis tools shiped with your database ie explain analyze for postgres.

  3. If it’s not db query related you can profile your app with django debug toolbar or django silk

  4. Above all before all the above check that you didn’t leave the debaugger on, stopped at some breakpoint.

Leave a comment