skillfed

django-pgactivity

Monitor, kill, and analyze Postgres queries.

django-pgactivity v1.8.0 1.4M downloads/30d#3,888 on PyPI46
Permissive license BSD-3-Clause AGING released

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-pgactivity

uv

uv add django-pgactivity

poetry

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 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

Framework :: DjangoFramework :: Django :: 4.2Framework :: Django :: 5.0Framework :: Django :: 5.1Framework :: Django :: 5.2Framework :: Django :: 6.0Intended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14

Tags

postgres query monitoring djangokill active postgres queriespg_stat_activity wrapperdjango database query inspectorpostgres connection managementquery timeout controldatabase activity monitoring
postgres-monitoringdjango-adminquery-control

More Monitoring packages

tqdm

Wraps any iterable to display a real-time…

copyleft · top 100 on PyPI

opentelemetry-semantic-conventions

Provides generated Python code for…

permissive · top 100 on PyPI

opentelemetry-sdk

Provides the reference implementation of the…

permissive · top 100 on PyPI

opentelemetry-api

Provides the abstract API and interfaces for…

permissive · top 100 on PyPI

opentelemetry-exporter-otlp-proto-http

Exports OpenTelemetry observability data to an…

permissive · top 1,000 on PyPI

opentelemetry-instrumentation

Provides automatic instrumentation commands and…

permissive · top 1,000 on PyPI

django-pglock

Provides Postgres advisory locks, table locks,…

permissive · top 5,000 on PyPI

django-zen-queries

Prevents unintended database queries in Django…

permissive · top 15,000 on PyPI

django-pgmigrate

Prevents migration downtime by detecting and…

permissive · top 5,000 on PyPI

django-query-builder

Builds and executes complex SQL queries…

permissive · top 15,000 on PyPI

django-pg-zero-downtime-migrations

Provides a Django database backend for…

permissive · top 15,000 on PyPI

django-health-check

Provides pluggable health check endpoints for…

permissive · top 5,000 on PyPI

django-queryinspect

Django middleware that logs and reports SQL…

permissive · top 15,000 on PyPI

postgres-mcp

A Model Context Protocol server that connects…

permissive · top 15,000 on PyPI

apache-airflow-providers-postgres

Integrates PostgreSQL databases with Apache…

permissive · top 5,000 on PyPI

django-constance

Django-constance lets you store and manage…

permissive · top 5,000 on PyPI