Skip to main content

A PostgreSQL profiler for Django that uses pg_stat_statements extension

Project description

django-pg-trunk

CircleCI PyPI Version Python Versions

A PostgreSQL query profiler for Django that uses pg_stat_statements extension.

Changelog

v0.1.0

  • Project is created.

Requirements

  • Python >= 3.7
  • PostgreSQL >= 13
  • Django >= 2.2

Installation

Install using pip:

pip install django-pg-trunk

Then add django_pg_trunk to your INSTALLED_APPS.

INSTALLED_APPS = [
    ...
    'django_pg_trunk',
]

django-pg-trunk will automatically install pg_stat_statements extension for PostgreSQL if it doesn't exist, however pg_stat_statements should be added to shared_preload_libraries in the PostgreSQL config. To do this, you can either run postgres server as following as in the test Docker Compose configuration:

postgres -c shared_preload_libraries=pg_stat_statements

or you should change postgresql.conf file manually and restart the postgres server. You can use the helper script to change postgresql.conf.

Usage

After installing the package, database queries can be examined under Pg Trunk > Query Statistics in Django admin.

Screen Shot 2022-01-23 at 14 08 23

Change view have more detailed statistics. All of the columns of pg_stat_statements can be found here.

Screen Shot 2022-01-23 at 14 09 01

A possible usecase of QueryStatistic model can be running a cron job that checks if there is a query that takes more time than a specific thershold, and send related alerts (emails, Slack notifications, etc.).

Contribution

As a first step, please open an issue about the feature/bug.

  • Development environment can be created using source scripts/run_development.sh.
  • Tests can be run using pytest command. Tests for different environments will be run on CircleCI.
  • Changes on Django Admin can be tested using python manage.py runserver 0:8000 in development Docker container and navigating to http://127.0.0.1/admin.

Project details


Download files

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

Source Distribution

django-pg-trunk-0.1.3.tar.gz (11.7 kB view hashes)

Uploaded Source

Built Distribution

django_pg_trunk-0.1.3-py3-none-any.whl (12.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page