Skip to main content

Psycopg2 logging / profiling tool

Project description

Psycopg2Logger

Psycopg2Logger is made to work with https://github.com/larswise/pgquerymon and is a logging library that captures PostgreSQL database queries from psycopg2 and transmits them via TCP to the 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.2.0.tar.gz (4.8 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.2.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for psycopg2logger-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2fe6205069edb5263687bfafdaf9eab3929a6187f651b6de9029c9cecfda607a
MD5 782de83d95af7980c050d791e507b249
BLAKE2b-256 d79ca2a3d3f0b42ae545e40f6f8d2476b41a893236712ee01e961be5abfcf2a4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: psycopg2logger-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ebe786ffb9fa485ba90ecde598c705d1181525480c60a73bf6207b98a20840b7
MD5 c468d803c7704ca6f3f51b7223e8b459
BLAKE2b-256 df4e8192a95d1e12dcbaec28781916dd61cd787e587788b61f16681bf463d1d0

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