PostgreSQL
 sql >> Database >  >> RDS >> PostgreSQL

Come si usa LoggingConnection di Psycopg2?

Sembra come impostare il connection_factory=LoggingConnection funziona

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