Skip to main content

Psycopg2 logging / profiling tool

Project description

Psycopg2Logger

Psycopg2Logger is a high-performance logging library that captures PostgreSQL database queries from psycopg2 and transmits them via TCP to a monitoring application in real-time. It provides detailed SQL query logging with parameter interpolation, execution duration tracking. The logger is optimized for development use with connection pooling, reflection caching, compiled regex patterns, and async logging to minimize performance impact on your application. Do not run this in production; this is intended for development only.

Installation

Install the package via pip:

pip install psycopg2sqllogger

Usage

For FastAPI Applications

from fastapi import FastAPI
from psycopg2logger.middleware import SQLInterceptorMiddleware

app = FastAPI()

# Add the middleware to your FastAPI application
app.add_middleware(SQLInterceptorMiddleware)

@app.get("/example")
async def example_endpoint():
    # Your database logic here
    return {"message": "Example endpoint"}

# Run your FastAPI application
# uvicorn main:app --reload

Performance Optimization

For high-throughput applications, you can disable certain features to improve performance:

app.add_middleware(SQLInterceptorMiddleware, enable_caller_detection=False)

Monitoring Application

To view the captured SQL queries, you'll need the companion monitoring application pgquerymon which provides a real-time dashboard for analyzing your database interactions.

Features

  • Real-time SQL logging with parameter interpolation
  • Execution duration tracking for performance analysis
  • Intelligent caller detection to identify source business logic
  • High-performance design with connection pooling and caching
  • Async logging to prevent blocking your application
  • Support for FastAPI applications
  • Configurable performance settings for different use cases

Configuration

Parameter Default Description
enable_caller_detection true Enable stack trace analysis (disable for better performance)

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

psycopg2logger-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

psycopg2logger-0.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file psycopg2logger-0.1.0.tar.gz.

File metadata

  • Download URL: psycopg2logger-0.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for psycopg2logger-0.1.0.tar.gz
Algorithm Hash digest
SHA256 403f3b2c1d671f04067821af24f967383cae129b5bdb245401738e1c93b75c32
MD5 9d1a4227a2b548247b4d7a6663dd9ffc
BLAKE2b-256 2a0a8e4b51a1dde077a0f8cb3ca59ddd317817ad1a0dea1a078e24768aee2864

See more details on using hashes here.

File details

Details for the file psycopg2logger-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: psycopg2logger-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for psycopg2logger-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9fca696278a0640b6a62a62b7125268ae75e0e88b95ebbc928197425c98d0f47
MD5 1720641e644aa3f1d7dc9bdf0dffb250
BLAKE2b-256 733081af090c77cacc6c07b984b9b234e448696112860cbca924eb08559e16d7

See more details on using hashes here.

Supported by

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