Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rMVj4-004ydr-S6 for psycopg@arkaria.postgresql.org; Sun, 07 Jan 2024 16:10:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rMVj2-00GWV5-2D for psycopg@arkaria.postgresql.org; Sun, 07 Jan 2024 16:10:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rMVj1-00GWUx-Oy for psycopg@lists.postgresql.org; Sun, 07 Jan 2024 16:10:11 +0000 Received: from mail-oa1-x30.google.com ([2001:4860:4864:20::30]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rMViy-000LYr-Oc for psycopg@postgresql.org; Sun, 07 Jan 2024 16:10:10 +0000 Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-20451ecbb80so628833fac.2 for ; Sun, 07 Jan 2024 08:10:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704643807; x=1705248607; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=9lh+6u4fwZ/jXJ66ExptIzbRqIO3AsFjh0lN/0ROIrc=; b=axcocreL/yGRHZtY+0pRtQQL8/wlI/JFenS+YE1Yfr6qDu6YpdrZ6bU6vpz9u+rz8e zZsrtak5QBA2u9GeRPXtv0AIDtanCqO4WCfKC9lf4/oF1BB53B+NhU9Gw+sbD7izR7IO r1iG7mmBD9I2T/c3sC4MTf3JwwIgDAJqYTZFx54IlTV36tp8hLJOj5T4ExVUiZUuDAfO XWX3vw8LFYnLRyB+Tqmcm3kiv7R2XF/e+3TuORmBYbNccW1bhOoxqMBZf1DNN+hISjfZ W/deawKowWA8VX5iVD7z5DvyrHqC7KzVnwpQejEhV07hEMAVEdFkuzGjvoIxIDqt2rof jVfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704643807; x=1705248607; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=9lh+6u4fwZ/jXJ66ExptIzbRqIO3AsFjh0lN/0ROIrc=; b=HIxVtEvNsTbl/xm4XsztnEFAqkKQlkqP9zqOHHWMdPfCGme3Eqbszi3vCJPCNCrV7s Pc6vA6FhLpkE0vtwQ+Xp2gxbLVFK2hXrDqrnyHY/TP8pW7vNk5BnaY98TGP+KA1cGS44 lVh5o50yIxLEC05uTK7M9XmMlMhWtq4PBHdJUlwq1f9mG3fkpcWwltA6R7HHlo75yHIu R0Z/3qmSlF5owXC7D2gAlCWrX46xyEBgpiJnd409XZGw3cz8n0j1jAPPI//jFt37GAI+ V7gewwqCG/oEFBp0lVz7a1iqUuBRutYW08H1MdZOS52ccMVVvbwsmwVSEQCA8x52I9s1 vNkA== X-Gm-Message-State: AOJu0Yy7Q7GBYzk3FD45ruHtzaa+Oj2pWuBoEKhmWB9mGjXXP+RifZGt lsY1b8W8gGYGxph8f/Gs0iNmTTySnahSd3ernWJufvRw10HJZw== X-Google-Smtp-Source: AGHT+IEsIzamAxDMfehcPztjSfCfiUA7uMtdChP6G9kk4oYO0S+4o+oEShlrE1Wm1R9atXY717f8oyQG7Fb548j5jQo= X-Received: by 2002:a05:6870:af49:b0:206:16d9:e76e with SMTP id uy9-20020a056870af4900b0020616d9e76emr1571416oab.33.1704643807056; Sun, 07 Jan 2024 08:10:07 -0800 (PST) MIME-Version: 1.0 From: Daniele Varrazzo Date: Sun, 7 Jan 2024 17:09:55 +0100 Message-ID: Subject: New releases, and happy new year! To: Psycopg Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello everyone, It's been a while that I haven't written to the ML, but I wanted to take the occasion of the first psycopg release of the new year to say hi :) I have just released psycopg 3.1.17 and psycopg-pool 3.2.1, containing only a few bug fixes but which I wanted to release soon to get quickly some feedback, as they address shortcomings in new developments. Changelogs with links to the issues at: - https://www.psycopg.org/psycopg3/docs/news.html#psycopg-3-1-17 - https://www.psycopg.org/psycopg3/docs/news_pool.html#psycopg-pool-3-2-1 For a recap of the last few development that happened in psycopg: since the inception of psycopg 3, the connection function uses the libpq async path, both in Python sync and async code. The async libpq connection function doesn't honour the connection timeout [1]; handling the timeout is not hard, but unfortunately, not handling it in the libpq, has undesirable repercussions with other libpq features: - multiple hosts in the connection string are not supported. The libpq will try the first but, without a timeout, it doesn't know when to give up on it and try the second. - Connecting to multiple hosts can also be implemented at DNS level, by associating more than one IP to the same hostname. - Where is the host specified? It can be in the connection string, or in an environment variable, but also in a service file. - A recent libpq feature is random hosts selection for load balancing [2]. Needless to say, it cannot work if we cannot try more than one host. We introduced multiple connection attempts in 3.1.13 (ticket #674) and released several regressions fixes and improvements in 3.1.15 and 3.1.16 (#694, #695, #703). In the just released 3.1.17 we moved DNS resolution to Python (#699) to cover the case of multiple IPs per host too. We were already performing name resolution in Python in order to allow non-blocking connection in async code (#259, released back in Psycopg 3.1.0), so now the sync and async connection code paths have become very similar. There is still a lingering problem though: if multiple hostnames or a hostname with multiple IPs are specified in a service file rather than in a connection param or an env var we will not handle them correctly (async connection will be blocking and limited to the first hit). Handling the service file would be a massive code duplication with the libpq, trying to replicate the same location customization, with some of the parameters that at best can be a guess (like the C macro SYSCONFDIR, of which I don't see a way to know at runtime if the pg_config binary is not on the client, and I'm not sure we want to call it). So it's a can of worms that hasn't been open yet, and it is making me wonder if it wouldn't be a better idea to improve the libpq instead. We could use the libpq if it provided: - support for attempt timeout in PQconnectPoll. Maybe this could be introduced by keeping the state of the attempts in the PGconn object; - customization of the getaddrinfo function in order to pass it a callback that we might override from Python. So I think I would check out if there is some desire to improve the libpq, before jumping in the reimplementation of the service file handling. On the connection pool front, in psycopg-pool 3.2.0 we introduced, among other new features, a callback to check the state of a connection on getconn (a request I have resisted to implement for some time, but which seems it became necessary because of the aggressive idle connections disconnection that either people are imposing on themselves or that just comes attached with postgres-as-a-service providers). In 3.2.1 we have improved the retry loop around this check function to avoid accidental busy loops (using the same backoff policy using in connections attempt). We hope that psycopg is serving you well. As usual, feedback is welcome and we thank you very much for your contributions (with good bug reports, features, ideas). Happy hacking and happy new year! -- Daniele [1]: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PQCONNECTSTARTPARAMS: "The connect_timeout connection parameter is ignored when using PQconnectPoll; it is the application's responsibility to decide whether an excessive amount of time has elapsed." [2] https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-LOAD-BALANCE-HOSTS