From: Daniele Varrazzo Date: Tue, 29 Apr 2025 14:14:40 +0000 (+0200) Subject: chore: add debug logging at connection time X-Git-Tag: 3.3.0.dev1~78^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f9c8046d6cb0330713624956ff39f0e4ed240b8;p=thirdparty%2Fpsycopg.git chore: add debug logging at connection time Only added to the Python implementation for the moment. See #888 --- diff --git a/psycopg/psycopg/generators.py b/psycopg/psycopg/generators.py index f7ade8a35..c77ebb13e 100644 --- a/psycopg/psycopg/generators.py +++ b/psycopg/psycopg/generators.py @@ -65,7 +65,14 @@ def _connect(conninfo: str, *, timeout: float = 0.0) -> PQGenConn[PGconn]: """ deadline = monotonic() + timeout if timeout else 0.0 + # To debug slowdown during connection: + # + # $ PSYCOPG_IMPL=python python + # >>> import logging + # >>> logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(message)s') + conn = pq.PGconn.connect_start(conninfo.encode()) + logger.debug("connection started: %s", conn) while True: if conn.status == BAD: encoding = conninfo_encoding(conninfo) @@ -74,6 +81,7 @@ def _connect(conninfo: str, *, timeout: float = 0.0) -> PQGenConn[PGconn]: ) status = conn.connect_poll() + logger.debug("connection polled: %s", conn) if status == POLL_READING or status == POLL_WRITING: wait = WAIT_R if status == POLL_READING else WAIT_W