details:   https://code.tryton.org/tryton/commit/877b2163d0cf
branch:    8.0
user:      Cédric Krier <[email protected]>
date:      Mon Jul 06 19:34:24 2026 +0200
description:
        Use NullConnectionPool for the default database

        The default database is template1 which is usually used to create new 
database.
        Keeping a pool of connection open on it prevents the creation of new 
database
        because exclusive access is needed on the template.

        Closes #14935
        (grafted from 20781078a519c45a7a1f70b0074c6abcb1a89589)
diffstat:

 trytond/pyproject.toml                         |   2 +-
 trytond/trytond/backend/postgresql/database.py |  12 +++++++++---
 2 files changed, 10 insertions(+), 4 deletions(-)

diffs (52 lines):

diff -r 6eab152447d8 -r 877b2163d0cf trytond/pyproject.toml
--- a/trytond/pyproject.toml    Mon Jul 06 19:15:08 2026 +0200
+++ b/trytond/pyproject.toml    Mon Jul 06 19:34:24 2026 +0200
@@ -39,7 +39,7 @@
 
 [project.optional-dependencies]
 Levenshtein = ['python-Levenshtein']
-PostgreSQL = ['psycopg[pool] >= 3']
+PostgreSQL = ['psycopg[pool] >= 3.1']
 barcode = ['python-barcode[images]']
 completion = ['argcomplete']
 coroutine = ['gevent >= 1.1']
diff -r 6eab152447d8 -r 877b2163d0cf 
trytond/trytond/backend/postgresql/database.py
--- a/trytond/trytond/backend/postgresql/database.py    Mon Jul 06 19:15:08 
2026 +0200
+++ b/trytond/trytond/backend/postgresql/database.py    Mon Jul 06 19:34:24 
2026 +0200
@@ -19,7 +19,7 @@
 from psycopg import connect
 from psycopg.errors import QueryCanceled as DatabaseTimeoutError
 from psycopg.sql import SQL, Identifier
-from psycopg_pool import ConnectionPool
+from psycopg_pool import ConnectionPool, NullConnectionPool
 from sql import Cast, Flavor, For, Literal, Table
 from sql.aggregate import Count
 from sql.conditionals import Coalesce
@@ -215,6 +215,8 @@
 
         minconn = config.getint('database', 'minconn', default=1)
         maxconn = config.getint('database', 'maxconn', default=64)
+        if name == _default_name:
+            minconn = 0
         timeout = config.getint('database', 'timeout')
         last_clean = (now - cls._clean_last).total_seconds()
         if last_clean > timeout:
@@ -230,12 +232,16 @@
                     kwargs = cls._connection_params(name)
                     kwargs['cursor_factory'] = LoggingCursor
                     conninfo = kwargs.pop('conninfo')
+                    if name == _default_name:
+                        Pool = NullConnectionPool
+                    else:
+                        Pool = ConnectionPool
                     try:
-                        inst._connpool = ConnectionPool(
+                        inst._connpool = Pool(
                             conninfo,
                             kwargs=kwargs,
                             open=True,
-                            check=ConnectionPool.check_connection,
+                            check=Pool.check_connection,
                             min_size=minconn, max_size=maxconn)
                     except Exception:
                         logger.error(

Reply via email to