diff --git a/SOURCES/postgresql-jdbc-9.2.1002-getIndexInfo-and-9.6-server.patch b/SOURCES/postgresql-jdbc-9.2.1002-getIndexInfo-and-9.6-server.patch
new file mode 100644
index 0000000..1efb239
--- /dev/null
+++ b/SOURCES/postgresql-jdbc-9.2.1002-getIndexInfo-and-9.6-server.patch
@@ -0,0 +1,35 @@
+This is backport of fixes from upstream pull request 560 and 569,
+excluding the testsuite fixes, namely commits:
+    3ff47daf68bf45694d5671eef1d9d32fb87f00d3
+    c9e5fc8bf53ead845f7b56c9cbe3c1058b636ca5
+Fixes rhbz#1547424
+
+
+diff --git a/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java b/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
+index f1109f5..fa4d6c0 100644
+--- a/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
++++ b/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
+@@ -4094,6 +4094,15 @@ public abstract class AbstractJdbc2DatabaseMetaData
+                 + "  END AS TYPE, "
+                 + "  (i.keys).n AS ORDINAL_POSITION, "
+                 + "  pg_catalog.pg_get_indexdef(ci.oid, (i.keys).n, false) AS COLUMN_NAME, "
++                + (connection.haveMinimumServerVersion("9.6")
++                ? "  CASE am.amname "
++                + "    WHEN 'btree' THEN CASE i.indoption[(i.keys).n - 1] & 1 "
++                + "      WHEN 1 THEN 'D' "
++                + "      ELSE 'A' "
++                + "    END "
++                + "    ELSE NULL "
++                + "  END AS ASC_OR_DESC, "
++                : ""
+                 + "  CASE am.amcanorder "
+                 + "    WHEN true THEN CASE i.indoption[(i.keys).n - 1] & 1 "
+                 + "      WHEN 1 THEN 'D' "
+@@ -4101,6 +4110,7 @@ public abstract class AbstractJdbc2DatabaseMetaData
+                 + "    END "
+                 + "    ELSE NULL "
+                 + "  END AS ASC_OR_DESC, "
++                )
+                 + "  ci.reltuples AS CARDINALITY, "
+                 + "  ci.relpages AS PAGES, "
+                 + "  pg_catalog.pg_get_expr(i.indpred, i.indrelid) AS FILTER_CONDITION "
diff --git a/SOURCES/postgresql-jdbc-9.2.1002-version-compare.patch b/SOURCES/postgresql-jdbc-9.2.1002-version-compare.patch
new file mode 100644
index 0000000..272d2dc
--- /dev/null
+++ b/SOURCES/postgresql-jdbc-9.2.1002-version-compare.patch
@@ -0,0 +1,62 @@
+The (pretty old) RHEL7 jdbc connector might well be run against newer
+PostgreSQL servers; newer than the system-default PostgreSQL 9.2,
+especially if we consider that we are asynchronously adding new servers
+into RHSCL channel.
+
+During the lifetime of postgresql-jdbc package, PostgreSQL upstream bumped
+major version from 9.6 to 10 (together with changing of the versioning
+scheme), which caused troubles with the implemented server-version
+comparator in pgjdbc; that code did not count with two-digit numbers in
+version string.  This patch fixes the problem downstream-only way, since
+backporting related upstream fixes would lead to much larger patch and
+risks that something goes wrong.  We still fallback to the old comparison
+method when we are not sure about the comparison (that is when isNewerOrEqual
+throws some exception).
+
+diff --git a/org/postgresql/jdbc2/AbstractJdbc2Connection.java b/org/postgresql/jdbc2/AbstractJdbc2Connection.java
+index 2fb37f4..d889247 100644
+--- a/org/postgresql/jdbc2/AbstractJdbc2Connection.java
++++ b/org/postgresql/jdbc2/AbstractJdbc2Connection.java
+@@ -1061,14 +1061,39 @@ public abstract class AbstractJdbc2Connection implements BaseConnection
+         }
+     }
+ 
++    private static boolean
++        isNewerOrEqual(String v1, String v2)
++    {
++        Iterator<String> i1 = Arrays.asList(v1.split("\\.")).iterator();
++        Iterator<String> i2 = Arrays.asList(v2.split("\\.")).iterator();
++
++        while (true) {
++            if (!i1.hasNext())
++                return true;
++            if (!i2.hasNext())
++                return false;
++
++            int left = Integer.parseInt(i1.next());
++            int right = Integer.parseInt(i2.next());
++
++            if (right == left)
++                continue;
++
++            return right >= left;
++        }
++    }
++
+     /**
+      * Is the server we are connected to running at least this version?
+-     * This comparison method will fail whenever a major or minor version
+-     * goes to two digits (10.3.0) or (7.10.1).
+      */
+     public boolean haveMinimumServerVersion(String ver)
+     {
+-        return (dbVersionNumber.compareTo(ver) >= 0);
++        try {
++            return isNewerOrEqual(ver, dbVersionNumber);
++        }
++        catch (Exception e) {
++            return (dbVersionNumber.compareTo(ver) >= 0);
++        }
+     }
+ 
+     /*
diff --git a/SPECS/postgresql-jdbc.spec b/SPECS/postgresql-jdbc.spec
index c52ae2c..bee7cbc 100644
--- a/SPECS/postgresql-jdbc.spec
+++ b/SPECS/postgresql-jdbc.spec
@@ -34,7 +34,7 @@
 Summary:	JDBC driver for PostgreSQL
 Name:		postgresql-jdbc
 Version:	9.2.1002
-Release:	5%{?dist}
+Release:	6%{?dist}
 # ASL 2.0 applies only to postgresql-jdbc.pom file, the rest is BSD
 License:	BSD and ASL 2.0
 Group:		Applications/Databases
@@ -44,6 +44,10 @@ Source0:	http://jdbc.postgresql.org/download/%{name}-%{upstreamver}.src.tar.gz
 # originally http://repo2.maven.org/maven2/postgresql/postgresql/8.4-701.jdbc4/postgresql-8.4-701.jdbc4.pom:
 Source1:	%{name}.pom
 
+# patches are self-documented inside the files
+Patch1:		postgresql-jdbc-9.2.1002-version-compare.patch
+Patch2:		postgresql-jdbc-9.2.1002-getIndexInfo-and-9.6-server.patch
+
 BuildArch:	noarch
 BuildRequires:	java-devel
 BuildRequires:	jpackage-utils
@@ -52,7 +56,7 @@ BuildRequires:	ant-junit
 BuildRequires:	junit
 # gettext is only needed if we try to update translations
 #BuildRequires:	gettext
-Requires:	java
+Requires:	java-headless
 Requires:	jpackage-utils
 
 %description
@@ -73,6 +77,9 @@ mv -f %{name}-%{upstreamver}.src/* .
 rm -f %{name}-%{upstreamver}.src/.gitignore
 rmdir %{name}-%{upstreamver}.src
 
+%patch1 -p1 -b .version
+%patch2 -p1 -b .getIndexInfo
+
 # remove any binary libs
 find -name "*.jar" -or -name "*.class" | xargs rm -f
 
@@ -123,6 +130,10 @@ install -d build/publicapi docs/%{name}
 %doc %{_javadocdir}/%{name}
 
 %changelog
+* Fri Apr 20 2018 Pavel Raiskup <praiskup@redhat.com> - 9.2.1002-6
+- fix incompatibility with 9.6+ (rhbz#1547424)
+- it's unnecessary to depend on whole java (rhbz#1406931)
+
 * Fri Dec 27 2013 Daniel Mach <dmach@redhat.com> - 9.2.1002-5
 - Mass rebuild 2013-12-27