Skip to main content

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.

Release files for django-pg-trunk 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-pg-trunk 0.1.3
File Size Uploaded
django-pg-trunk-0.1.3.tar.gz 11.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-pg-trunk 0.1.3
File Interpreter ABI Platform
django_pg_trunk-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 24.1 kB

Release files / django-pg-trunk-0.1.3.tar.gz

Download URL django-pg-trunk-0.1.3.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ffa31c1e65737b4575f379e2e4757d848577ebb41d2511b111b0a9c754a10a5e
BLAKE2b-256 checksum
How to use checksums
67775b927f56d5ba4ced70f221992022a938a97022e1609d8e39ff0921e07a0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

Release files / django_pg_trunk-0.1.3-py3-none-any.whl

Download URL django_pg_trunk-0.1.3-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b0363a5575a36ec1136721ce534776f365fb9b163bcf6afef1e8efdbc2b8e728
BLAKE2b-256 checksum
How to use checksums
b1c3df951737e2cd27b63286a6e4f49ace62e4040129536ef4ebd88dacd601ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page