Thread: JDBC driver 9.2 sending arbitrary timezone

JDBC driver 9.2 sending arbitrary timezone

From
Alexandre Gattiker
Date:
Hello,

PostgreSQL jdbc jar 9.2-1003-jdbc4 is failing for me, while version 9.1-901-1.jdbc4 works fine. I was able to reproduce the issue by running the jdbc driver's unit tests.

It appears the client is sending to the server the timezone Europe/Busingen, although my timezone is set to Europe/Zurich.

runtest:
    [junit] Testsuite: org.postgresql.test.jdbc2.Jdbc2TestSuite
    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
    [junit] 
    [junit] Null Test:  Caused an ERROR
    [junit] null
    [junit] java.lang.reflect.InvocationTargetException
    [junit] Caused by: org.postgresql.util.PSQLException: FATAL: invalid value for parameter "TimeZone": "Europe/Busingen"
    [junit] at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionFactoryImpl.java:572)
    [junit] at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:177)
    [junit] at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64)
    [junit] at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:136)
    [junit] at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:29)
    [junit] at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:21)
    [junit] at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:31)
    [junit] at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)
    [junit] at org.postgresql.Driver.makeConnection(Driver.java:406)
    [junit] at org.postgresql.Driver.connect(Driver.java:280)
    [junit] at java.sql.DriverManager.getConnection(DriverManager.java:571)
    [junit] at java.sql.DriverManager.getConnection(DriverManager.java:187)
    [junit] at org.postgresql.test.TestUtil.openDB(TestUtil.java:187)
    [junit] at org.postgresql.test.TestUtil.openDB(TestUtil.java:173)
    [junit] at org.postgresql.test.jdbc2.Jdbc2TestSuite.suite(Jdbc2TestSuite.java:94)
    [junit] ... 25 more



Server: Postgres Plus; PostgreSQL 9.2.1 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-52), 64-bit
CentOS release 6.4 (Final) Linux 2.6.32-358.11.1.el6.x86_64 #1 SMP Wed Jun 12 03:34:52 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

cat /etc/sysconfig/clock 
ZONE="Europe/Zurich"

Regards,
Alexandre

Re: JDBC driver 9.2 sending arbitrary timezone

From
Tom Lane
Date:
Alexandre Gattiker <agattiker@gmail.com> writes:
> PostgreSQL jdbc jar 9.2-1003-jdbc4 is failing for me, while version
> 9.1-901-1.jdbc4 works fine. I was able to reproduce the issue by running
> the jdbc driver's unit tests.
> It appears the client is sending to the server the
> timezone Europe/Busingen, although my timezone is set to Europe/Zurich.

According to the Olsen timezone database, Europe/Busingen is an alias for
Europe/Zurich.  So while it's an interesting question why the client side
is sending "Europe/Busingen" not "Europe/Zurich", you should get the same
result either way.  And it's not hard to imagine that there might be
logic somewhere inside Java that causes one to be substituted for the
other.

However, a look into the Olsen source files suggests that Europe/Busingen
was only added as a zone name in 2011.  When was your last server update?
I don't know whether EDB relies on the system tzdata package, so either
the postgres package or the tzdata package might be old ...

            regards, tom lane


Re: JDBC driver 9.2 sending arbitrary timezone

From
Alexandre Gattiker
Date:
It appears that the timezone is set at CentOS installation by copying /usr/share/zoneinfo/Europe/Zurich to /etc/localtime. At runtime, when the JDBC driver calls TimeZone.getDefault(), the JRE appears to search all files in the CentOS timezone db (/usr/share/zoneinfo/) until it founds one that is identical to the one in /etc/localtime. So the result is randomly Europe/Zurich or Europe/Busingen, since both files are identical in /usr/share/zoneinfo. If the timezone is set by doing "ln -sf /usr/share/zoneinfo/Europe/Zurich /etc/localtime", the JRE finds the intended one directly.

In any case, upgrading to the latest PostgreSQL version also solved it.

Thanks for your help,
Alexandre


On Mon, Aug 5, 2013 at 8:16 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Alexandre Gattiker <agattiker@gmail.com> writes:
> PostgreSQL jdbc jar 9.2-1003-jdbc4 is failing for me, while version
> 9.1-901-1.jdbc4 works fine. I was able to reproduce the issue by running
> the jdbc driver's unit tests.
> It appears the client is sending to the server the
> timezone Europe/Busingen, although my timezone is set to Europe/Zurich.

According to the Olsen timezone database, Europe/Busingen is an alias for
Europe/Zurich.  So while it's an interesting question why the client side
is sending "Europe/Busingen" not "Europe/Zurich", you should get the same
result either way.  And it's not hard to imagine that there might be
logic somewhere inside Java that causes one to be substituted for the
other.

However, a look into the Olsen source files suggests that Europe/Busingen
was only added as a zone name in 2011.  When was your last server update?
I don't know whether EDB relies on the system tzdata package, so either
the postgres package or the tzdata package might be old ...

                        regards, tom lane