django-pgactivity
Monitor, kill, and analyze Postgres queries.
What it is and what it does
django-pgactivity is a Django package that wraps PostgreSQL's pg_stat_activity view to give you visibility into active database queries. It provides a management command to list, filter, and control queries (cancel or terminate them), a proxy model for programmatic access, and optional middleware that attaches request metadata (URL, method) to queries so you can trace them back to your application code. You can also dynamically set statement timeouts on code blocks to prevent long-running queries.
The package is designed for Django projects using PostgreSQL and targets developers who need to monitor, debug, or manage database activity at runtime. It depends only on django and installs as a wheel with no compiled dependencies, making it straightforward to add to an existing project.
Use it for:
- Identify and terminate runaway or long-running queries during production incidents.
- Debug slow endpoints by correlating slow queries with request URLs via attached context.
- Enforce query timeouts on specific operations to prevent resource exhaustion.
- Monitor idle-in-transaction connections that may be holding locks.
- Inspect active query SQL and connection metadata from a Django management command.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides Django management commands and utilities to view, filter, cancel, and terminate active PostgreSQL queries, plus middleware for annotating queries with application context.
Yes, if you run Django with PostgreSQL and need runtime visibility into database queries. The low install friction, permissive license, and active (if aging) maintenance make it a practical choice for production monitoring and debugging. No known vulnerabilities and broad Python/Django version support strengthen the case. The 257-day gap since last release is worth noting but not disqualifying given the repository remains active.
Install
django-pgactivity on PyPI
pip
pip install django-pgactivityuv
uv add django-pgactivitypoetry
poetry add django-pgactivityInstalling django-pgactivity
Before you install
Low install friction with a single dependency on django. Maintenance status is aging—last release was 257 days ago—but the repository remains active and the package supports current Python and Django versions.
License in practice
BSD-3-Clause is permissive; you can use this package in commercial and proprietary projects with minimal restrictions.
Quickstart
pip install django-pgactivity
# Add 'pgactivity' to INSTALLED_APPS in settings.py
# Then use the management command:
python manage.py pgactivity
# Or in code:
from pgactivity.models import PGActivity
for activity in PGActivity.objects.all():
print(activity.pid, activity.state)
Requires PostgreSQL database backend and Django project setup; works with Python 3.10 or later.
Verify before relying
- Whether the package works reliably with all advertised Django versions (4.2–6.0) in production environments.
- Performance impact of the middleware on high-traffic applications.
- Whether context annotation works correctly with async Django views.
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (<4,>=3.10.0) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — django |
| Maintenance | aging — 257 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,448,451/month — #3,888 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_pgactivity-1.8.0-py3-none-any.whl
Tags
More Monitoring packages
Wraps any iterable to display a real-time…
copyleft · top 100 on PyPI
opentelemetry-semantic-conventionsProvides generated Python code for…
permissive · top 100 on PyPI
opentelemetry-sdkProvides the reference implementation of the…
permissive · top 100 on PyPI
opentelemetry-apiProvides the abstract API and interfaces for…
permissive · top 100 on PyPI
opentelemetry-exporter-otlp-proto-httpExports OpenTelemetry observability data to an…
permissive · top 1,000 on PyPI
opentelemetry-instrumentationProvides automatic instrumentation commands and…
permissive · top 1,000 on PyPI
django-pglockProvides Postgres advisory locks, table locks,…
permissive · top 5,000 on PyPI
django-zen-queriesPrevents unintended database queries in Django…
permissive · top 15,000 on PyPI
django-pgmigratePrevents migration downtime by detecting and…
permissive · top 5,000 on PyPI
django-query-builderBuilds and executes complex SQL queries…
permissive · top 15,000 on PyPI
django-pg-zero-downtime-migrationsProvides a Django database backend for…
permissive · top 15,000 on PyPI
django-health-checkProvides pluggable health check endpoints for…
permissive · top 5,000 on PyPI
django-queryinspectDjango middleware that logs and reports SQL…
permissive · top 15,000 on PyPI
postgres-mcpA Model Context Protocol server that connects…
permissive · top 15,000 on PyPI
apache-airflow-providers-postgresIntegrates PostgreSQL databases with Apache…
permissive · top 5,000 on PyPI
django-constanceDjango-constance lets you store and manage…
permissive · top 5,000 on PyPI