From dd0fe1cd9293d8ca11c4793467cee27bbf9a98a5 Mon Sep 17 00:00:00 2001
From: "d.kovalenko" <dmitry.lipetsk@gmail.com>
Date: Mon, 7 Apr 2025 08:02:24 +0300
Subject: [PATCH 1/2] OsOperation::db_connect is removed

OsOperation does not work with databases. It provides an only OS functional.
---
 testgres/connection.py            | 12 +++++++-----
 testgres/operations/local_ops.py  | 13 +------------
 testgres/operations/os_ops.py     | 12 ------------
 testgres/operations/remote_ops.py | 20 --------------------
 4 files changed, 8 insertions(+), 49 deletions(-)

diff --git a/testgres/connection.py b/testgres/connection.py
index ccedd135..fa463dbb 100644
--- a/testgres/connection.py
+++ b/testgres/connection.py
@@ -42,11 +42,13 @@ def __init__(self,
 
         self._node = node
 
-        self._connection = node.os_ops.db_connect(dbname=dbname,
-                                                  user=username,
-                                                  password=password,
-                                                  host=node.host,
-                                                  port=node.port)
+        self._connection = pglib.connect(
+            dbname=dbname,
+            user=username,
+            password=password,
+            host=node.host,
+            port=node.port
+        )
 
         self._connection.autocommit = autocommit
         self._cursor = self.connection.cursor()
diff --git a/testgres/operations/local_ops.py b/testgres/operations/local_ops.py
index 39c81405..9785d462 100644
--- a/testgres/operations/local_ops.py
+++ b/testgres/operations/local_ops.py
@@ -12,7 +12,7 @@
 
 from ..exceptions import ExecUtilException
 from ..exceptions import InvalidOperationException
-from .os_ops import ConnectionParams, OsOperations, pglib, get_default_encoding
+from .os_ops import ConnectionParams, OsOperations, get_default_encoding
 from .raise_error import RaiseError
 from .helpers import Helpers
 
@@ -446,14 +446,3 @@ def is_port_free(self, number: int) -> bool:
                 return True
             except OSError:
                 return False
-
-    # Database control
-    def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
-        conn = pglib.connect(
-            host=host,
-            port=port,
-            database=dbname,
-            user=user,
-            password=password,
-        )
-        return conn
diff --git a/testgres/operations/os_ops.py b/testgres/operations/os_ops.py
index 489a7cb2..d25e76bc 100644
--- a/testgres/operations/os_ops.py
+++ b/testgres/operations/os_ops.py
@@ -1,14 +1,6 @@
 import getpass
 import locale
 
-try:
-    import psycopg2 as pglib  # noqa: F401
-except ImportError:
-    try:
-        import pg8000 as pglib  # noqa: F401
-    except ImportError:
-        raise ImportError("You must have psycopg2 or pg8000 modules installed")
-
 
 class ConnectionParams:
     def __init__(self, host='127.0.0.1', port=None, ssh_key=None, username=None):
@@ -130,7 +122,3 @@ def get_process_children(self, pid):
     def is_port_free(self, number: int):
         assert type(number) == int  # noqa: E721
         raise NotImplementedError()
-
-    # Database control
-    def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
-        raise NotImplementedError()
diff --git a/testgres/operations/remote_ops.py b/testgres/operations/remote_ops.py
index ee747e52..25d02f38 100644
--- a/testgres/operations/remote_ops.py
+++ b/testgres/operations/remote_ops.py
@@ -6,15 +6,6 @@
 import io
 import logging
 
-# we support both pg8000 and psycopg2
-try:
-    import psycopg2 as pglib
-except ImportError:
-    try:
-        import pg8000 as pglib
-    except ImportError:
-        raise ImportError("You must have psycopg2 or pg8000 modules installed")
-
 from ..exceptions import ExecUtilException
 from ..exceptions import InvalidOperationException
 from .os_ops import OsOperations, ConnectionParams, get_default_encoding
@@ -677,17 +668,6 @@ def _is_port_free__process_1(error: str) -> bool:
         #
         return True
 
-    # Database control
-    def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
-        conn = pglib.connect(
-            host=host,
-            port=port,
-            database=dbname,
-            user=user,
-            password=password,
-        )
-        return conn
-
     @staticmethod
     def _make_exec_env_list() -> list[str]:
         result = list[str]()

From 28058e3ba15805e6eeb64e3d2928e422d153f0c8 Mon Sep 17 00:00:00 2001
From: "d.kovalenko" <dmitry.lipetsk@gmail.com>
Date: Mon, 7 Apr 2025 10:58:59 +0300
Subject: [PATCH 2/2] [FIX] The call of pglib.connect is corrected [arg:
 database]

pg8000 does not support dbname arg.

A problem was detected with internal tests.

TODO: CI must explicitly test pg8000 and psycopg2.
---
 testgres/connection.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testgres/connection.py b/testgres/connection.py
index fa463dbb..b8dc49a9 100644
--- a/testgres/connection.py
+++ b/testgres/connection.py
@@ -43,7 +43,7 @@ def __init__(self,
         self._node = node
 
         self._connection = pglib.connect(
-            dbname=dbname,
+            database=dbname,
             user=username,
             password=password,
             host=node.host,