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.2.7^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55965e71b4bf4de56c5c6621ce5c9a91f1c8c3e0;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 2cd15c37d..bf4f03486 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