7ef03e
The (pretty old) RHEL7 jdbc connector might well be run against newer
7ef03e
PostgreSQL servers; newer than the system-default PostgreSQL 9.2,
7ef03e
especially if we consider that we are asynchronously adding new servers
7ef03e
into RHSCL channel.
7ef03e
7ef03e
During the lifetime of postgresql-jdbc package, PostgreSQL upstream bumped
7ef03e
major version from 9.6 to 10 (together with changing of the versioning
7ef03e
scheme), which caused troubles with the implemented server-version
7ef03e
comparator in pgjdbc; that code did not count with two-digit numbers in
7ef03e
version string.  This patch fixes the problem downstream-only way, since
7ef03e
backporting related upstream fixes would lead to much larger patch and
7ef03e
risks that something goes wrong.  We still fallback to the old comparison
7ef03e
method when we are not sure about the comparison (that is when isNewerOrEqual
7ef03e
throws some exception).
7ef03e
7ef03e
diff --git a/org/postgresql/jdbc2/AbstractJdbc2Connection.java b/org/postgresql/jdbc2/AbstractJdbc2Connection.java
7ef03e
index 2fb37f4..d889247 100644
7ef03e
--- a/org/postgresql/jdbc2/AbstractJdbc2Connection.java
7ef03e
+++ b/org/postgresql/jdbc2/AbstractJdbc2Connection.java
7ef03e
@@ -1061,14 +1061,39 @@ public abstract class AbstractJdbc2Connection implements BaseConnection
7ef03e
         }
7ef03e
     }
7ef03e
 
7ef03e
+    private static boolean
7ef03e
+        isNewerOrEqual(String v1, String v2)
7ef03e
+    {
7ef03e
+        Iterator<String> i1 = Arrays.asList(v1.split("\\.")).iterator();
7ef03e
+        Iterator<String> i2 = Arrays.asList(v2.split("\\.")).iterator();
7ef03e
+
7ef03e
+        while (true) {
7ef03e
+            if (!i1.hasNext())
7ef03e
+                return true;
7ef03e
+            if (!i2.hasNext())
7ef03e
+                return false;
7ef03e
+
7ef03e
+            int left = Integer.parseInt(i1.next());
7ef03e
+            int right = Integer.parseInt(i2.next());
7ef03e
+
7ef03e
+            if (right == left)
7ef03e
+                continue;
7ef03e
+
7ef03e
+            return right >= left;
7ef03e
+        }
7ef03e
+    }
7ef03e
+
7ef03e
     /**
7ef03e
      * Is the server we are connected to running at least this version?
7ef03e
-     * This comparison method will fail whenever a major or minor version
7ef03e
-     * goes to two digits (10.3.0) or (7.10.1).
7ef03e
      */
7ef03e
     public boolean haveMinimumServerVersion(String ver)
7ef03e
     {
7ef03e
-        return (dbVersionNumber.compareTo(ver) >= 0);
7ef03e
+        try {
7ef03e
+            return isNewerOrEqual(ver, dbVersionNumber);
7ef03e
+        }
7ef03e
+        catch (Exception e) {
7ef03e
+            return (dbVersionNumber.compareTo(ver) >= 0);
7ef03e
+        }
7ef03e
     }
7ef03e
 
7ef03e
     /*