--- id: django-pgactivity version: "1.8.0" license: BSD-3-Clause license_treatment: permissive maintenance: aging --- # django-pgactivity — Monitor, kill, and analyze Postgres queries. License: permissive · Maintenance: aging · Downloads: 1.4M/mo ## 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 above — 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 pip install django-pgactivity uv add django-pgactivity poetry add django-pgactivity ## Installing 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_current - Install friction: low - Maintenance: aging - Downloads: 1.4M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags postgres query monitoring django, kill active postgres queries, pg_stat_activity wrapper, django database query inspector, postgres connection management, query timeout control, database activity monitoring, postgres-monitoring, django-admin, query-control [View on SkillFed](https://skillfed.io/packages/django-pgactivity) · [View on PyPI](https://pypi.org/project/django-pgactivity/)