Thread: JDBC driver returns different version strings on Ubuntu and CentOS

JDBC driver returns different version strings on Ubuntu and CentOS

From
Thomas Kellerer
Date:
I have just noticed that DatabaseMetaData.getDatabaseProductVersion() returns the String "10.2.2" when connected to a
serverrunning on Ubuntu, but returns "10.2" when connected to a server running on CentOS or Windows. 
 

Is there a specific reason for this? 

It's a bit confusing because 10.2.2 doesn't actually exists as a "real" Postgres version.

This happens with the driver versions 42.1.4 and 42.2.1 (haven tried others)

Regards
Thomas
 



Re: JDBC driver returns different version strings on Ubuntu and CentOS

From
Jorge Solórzano
Date:
The DatabaseMetaData.getDatabaseProductVersion() returns the exact string of ParameterStatus "server_version", and this version can be different from ditro to distro, in my Ubuntu the "server_version" returns: "10.2 (Ubuntu 10.2-1.pgdg16.04+1)". In other words the version returned is not "parsed/cleaned", and if you need to implement some logic based on the version, is better to use getDatabaseMajorVersion() and getDatabaseMinorVersion().

Regards.

On Mon, Feb 19, 2018 at 9:52 AM, Thomas Kellerer <spam_eater@gmx.net> wrote:
I have just noticed that DatabaseMetaData.getDatabaseProductVersion() returns the String "10.2.2" when connected to a server running on Ubuntu, but returns "10.2" when connected to a server running on CentOS or Windows.

Is there a specific reason for this?

It's a bit confusing because 10.2.2 doesn't actually exists as a "real" Postgres version.

This happens with the driver versions 42.1.4 and 42.2.1 (haven tried others)

Regards
Thomas




Re: JDBC driver returns different version strings on Ubuntu andCentOS

From
Thomas Kellerer
Date:
Hmm, there must be _some_ parsing going on, because 

   select current_setting('server_version')

returns "10.2 (Ubuntu 10.2-1.pgdg16.04+1)" on the Ubuntu installation, so I wonder how the 10.2.2 is created from that
bythe JDBC driver. 
 

It is not really important, I am just wondering...

Regards
Thomas
 

Jorge Solórzano schrieb am 19.02.2018 um 18:04:
> The DatabaseMetaData.getDatabaseProductVersion() returns the exact
> string of ParameterStatus "server_version", and this version can be
> different from ditro to distro, in my Ubuntu the "server_version"
> returns: "10.2 (Ubuntu 10.2-1.pgdg16.04+1)". In other words the
> version returned is not "parsed/cleaned", and if you need to
> implement some logic based on the version, is better to use
> getDatabaseMajorVersion() and getDatabaseMinorVersion().
> 
> Regards.
> 
> On Mon, Feb 19, 2018 at 9:52 AM, Thomas Kellerer <spam_eater@gmx.net <mailto:spam_eater@gmx.net>> wrote:
> 
>     I have just noticed that DatabaseMetaData.getDatabaseProductVersion() returns the String "10.2.2" when connected
toa server running on Ubuntu, but returns "10.2" when connected to a server running on CentOS or Windows.
 
> 
>     Is there a specific reason for this?
> 
>     It's a bit confusing because 10.2.2 doesn't actually exists as a "real" Postgres version.
> 
>     This happens with the driver versions 42.1.4 and 42.2.1 (haven tried others)
> 
>     Regards
>     Thomas
> 
> 
> 
> 




Re: JDBC driver returns different version strings on Ubuntu and CentOS

From
Vladimir Sitnikov
Date:
>I am just wondering...

It should be the value as is: https://github.com/pgjdbc/pgjdbc/blob/45c32bc6af2e140ff86dabd718344c74fc244394/pgjdbc/src/main/java/org/postgresql/core/v3/QueryExecutorImpl.java#L2637 

Would you capture a connection trace? I mean loggerLevel=TRACE&loggerFile=pgjdbc-trace.log
It would contain actual values that the server sends to the client in the handshake packets.

Vladimir

Re: JDBC driver returns different version strings on Ubuntu andCentOS

From
Thomas Kellerer
Date:
Vladimir Sitnikov schrieb am 20.02.2018 um 10:45:
>>I am just wondering...
> 
> It should be the value as is:
https://github.com/pgjdbc/pgjdbc/blob/45c32bc6af2e140ff86dabd718344c74fc244394/pgjdbc/src/main/java/org/postgresql/core/v3/QueryExecutorImpl.java#L2637 
> 
> Would you capture a connection trace? I mean loggerLevel=TRACE&loggerFile=pgjdbc-trace.log
> It would contain actual values that the server sends to the client in the handshake packets.

Sure, no problem.

I ran the following simple program: 

    String url = "jdbc:postgresql://hostname/postgres?loggerLevel=TRACE&loggerFile=c:/temp/pg/pgjdbc-trace.log";
    Connection con = DriverManager.getConnection(url, "...", "...");
    String version = con.getMetaData().getDatabaseProductVersion();
    System.out.println(version);
    con.close();

I have attached the logfiles for the connection to Ubuntu and CentOS. 

I can however not see the version string in those logfiles. 

Thomas




Attachment

Re: JDBC driver returns different version strings on Ubuntu and CentOS

From
Jorge Solórzano
Date:
On Wed, Feb 21, 2018 at 1:40 AM, Thomas Kellerer <spam_eater@gmx.net> wrote:

I can however not see the version string in those logfiles.

 
​For CentOS is:
<=BE ParameterStatus(server_version = 10.2)
For Ubuntu is:
<=BE ParameterStatus(server_version = 10.2 (Ubuntu 10.2-1.pgdg16.04+1))
 
​Not sure where you get "10.2.2"​.


Re: JDBC driver returns different version strings on Ubuntu andCentOS

From
Thomas Kellerer
Date:
Jorge Solórzano schrieb am 21.02.2018 um 18:33:
> On Wed, Feb 21, 2018 at 1:40 AM, Thomas Kellerer <spam_eater@gmx.net <mailto:spam_eater@gmx.net>> wrote:
> 
> ​For CentOS is:
> 
> <=BE ParameterStatus(server_version = 10.2)
> 
> For Ubuntu is:
> 
> <=BE ParameterStatus(server_version = 10.2 (Ubuntu 10.2-1.pgdg16.04+1))
> 
> ​
> 
> ​Not sure where you get "10.2.2"​.

As I said, that's the return value of DatabaseMetaData.getDatabaseProductVersion()

So apparently there *is* some parsing going on.





Re: JDBC driver returns different version strings on Ubuntu and CentOS

From
Jorge Solórzano
Date:

On Wed, Feb 21, 2018 at 11:43 AM, Thomas Kellerer <spam_eater@gmx.net> wrote:

As I said, that's the return value of DatabaseMetaData.
​​
getDatabaseProductVersion()

So apparently there *is* some parsing going on.


The receiveParameterStatus() of QueryExecutorImpl calls setServerVersion(value) of QueryExecutorBase:
https://github.com/pgjdbc/pgjdbc/blob/45c32bc6af2e140ff86dabd718344c74fc244394/pgjdbc/src/main/java/org/postgresql/core/v3/QueryExecutorImpl.java#L2637
 
There is no parsing going on.​

In my Ubuntu 
getDatabaseProductVersion() returns "10.2 (Ubuntu 10.2-1.pgdg16.04+1)".

Re: JDBC driver returns different version strings on Ubuntu and CentOS

From
Vladimir Sitnikov
Date:
>DatabaseMetaData.getDatabaseProductVersion()

Would you add a breakpoint to that method and capture a screenshot?

The code should just take a server_version as is and return it as is.

Vladimir