Seems like setting the connection_factory=LoggingConnection
works
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")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…