Skip to main content

A Django app that exposes a bunch of PostgreSQL database metrics.

Project description


GitHub Build Status Codecov coverage Read the Docs Version License: BSD Python Versions: see Django Versions: see

A Django application that exposes a bunch of PostgreSQL database metrics.


At PyCon Canada 2017 Craig Kerstiens gave a talk "Postgres at any scale". In his talk Craig pointed out a bunch of metrics one should look at to understand why a PostgreSQL database could be "slow" or not perform as expected.

This project adds a Django Admin view exposing these metrics to Django users with the is_superusers flag turned on.


Start by installing django-postgres-metrics from PyPI:

(env)$ python -m pip install django-postgres-metrics

You will also need to make sure to have psycopg2 installed which is already a requirement by Django for PostgreSQL support anyway.

Then you need to add postgres_metrics to your INSTALLED_APPS list. Due to the way django-postgres-metrics works, you need to include it _before* the admin app:


You also need to make sure that the request context processor is included in the TEMPLATES setting. It is included by default for projects that were started on Django 1.8 or later:

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'OPTIONS': {
            'context_processors': [

Lastly, you need to add a URL path to your global before the admin URL patterns.

For Django 2.0 and up:

from django.urls import include, path

urlpatterns = [
    path('admin/postgres-metrics/', include('postgres_metrics.urls')),

This is what a metric could look like: Screenshot of the Detailed Index Usage metric, with help text, and a table with rows for each index


If you found or if you think you found a security issue please get in touch via info+django-postgres-metrics *at* markusholtermann *dot* eu.

I'm working about this in my free time. I don't have time to monitor the email 24/7. But you should normally receive a response within a week. If I haven't got back to you within 2 weeks, please reach out again.


The project black and isort for formatting its code. flake8 is used for linting. All these are combined into pre-commit to run before each commit and push. To set it up:

(env)$ python -m pip install '.[dev,test]'
(env)$ pre-commit install -t pre-commit -t pre-push --install-hooks

To run the unit tests:

(env)$ test -v 2 --settings=tests.settings

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-postgres-metrics, version 0.11.0
Filename, size File type Python version Upload date Hashes
Filename, size django_postgres_metrics-0.11.0-py3-none-any.whl (17.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size django-postgres-metrics-0.11.0.tar.gz (112.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page