PostgreSQL
 sql >> Datenbank >  >> RDS >> PostgreSQL

Wie verwende ich die LoggingConnection von Psycopg2?

Scheint wie das Setzen von connection_factory=LoggingConnection funktioniert

import logging
import psycopg2
from psycopg2.extras import LoggingConnection

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

db_settings = {
    "user": "abcd",
    "password": "efgh",
    "host": "postgres.db",
    "database": "dev",
}

conn = psycopg2.connect(connection_factory=LoggingConnection, **db_settings)
conn.initialize(logger)

cur = conn.cursor()
cur.execute("SELECT * FROM table LIMIT 5")