]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
chore: add debug logging at connection time
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 29 Apr 2025 14:14:40 +0000 (16:14 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 29 Apr 2025 16:07:44 +0000 (18:07 +0200)
Only added to the Python implementation for the moment.

See #888

psycopg/psycopg/generators.py

index 2cd15c37d1b09d7aee81466a711a89f8db0941b4..bf4f03486ccd91fc632e6eec8d1bfc3a995c527a 100644 (file)
@@ -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