New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prepared statement pool and Daylight Saving Time #130
Comments
Any thoughts on why this would happen with pg and not the rest? I am thinking it has something to do with us not being threaded. Connections are actually processes and they may not see the new timezone ? That being said turning off statement caching should exhibit the same problem if the above were true ? |
Can you give more details what needs to be tests? turning off statement caching on DB configuration level ? The test above will fail in PST time zone with the same data. |
What I'd like to see is what the server sees. Can you get the server logs Dave Cramer On Sun, Mar 16, 2014 at 3:27 PM, Vlad Skarzhevskyy <notifications@github.com
|
log_min_duration_statement =0 error in java I modified SQL where trc is try# so we will see it in trace. |
I cloned your github version and ran ant test. There were no errors. This Are you saying it only happens with the versions and specific OS mentioned Dave Cramer On Sun, Mar 16, 2014 at 3:58 PM, Vlad Skarzhevskyy <notifications@github.com
|
I see now why this bug was not discovered before:) Windows 7 64 bit on i7-4930K or i7-2860QM (different computers) Ubuntu 12.04.4 64 bit running in VMware ESX and VMware Workstation (8, 4 cores or 1 core given to VM) Additional dependencies for ant build wget http://search.maven.org/remotecontent?filepath=org/apache/commons/commons-dbcp2/2.0/commons-dbcp2-2.0.jar I can only try to run the same tests on Mac in one week. I will ask DBA to reproduce the problem on PostgreSQL 9.2.x on some other version of Linux. |
I would suggest eliminating all pooling and seeing if the bug is still David J. EDIT: My bad, responded without reading...pooling is configurable and indeed is a component of the problem. |
Also, why are you using "dval timestamp" when you obviously care about timezone information? "timestamptz" or "timestamp with time zone" are the appropriate types here. Maybe the combination of pooling and data type are causing an adverse reaction? |
No Statements pooling - no problem. the reason why I use 'timestamp without time zone' is the application itself. It is SAS different clients - different time zones. I may consider changing it depending on outcome of this thread. |
Here are my test results, bug confirmed, hope it helps. |
Somehow when the prepared select statement becomes named the issue manifests. No pool required to replicate the behavior (in theory, haven't had a chance to setup an test it myself). Its does seem isolated to the driver since a simple: PREPARE s1 AS SELECT ('2014-03-09 06:21:28 EDT'::timestamptz)::time; Returns "06:21:28" as expected. The issue seems to have to reside at converting whatever response the server is providing into java.sql.Timestamp instance. I don't see how threading the "new time zone" have any play; a store non-time-zoned time is coming back as two different values depending on whether the select statement has been executed via a named prepared statement. |
For those who haven't run this can someone dump some ResultMetaData information for both the good and bad results to see what the result thinks it is dealing with. EDIT: And just for kicks make the query: SELECT dval, dval::text AS dval_text FROM test WHERE name = ?; It's nice to see what PostgreSQL thinks without having to go through translation. Thanks! |
As suggested by David |
tested this: prepareStatement("SELECT val, val::text AS val_text FROM dls1test"); |
OK, So I have narrowed it down to: The first 4 executions use Strings, The 5 switches to binary, then I am Dave Cramer On Sat, Mar 22, 2014 at 9:54 PM, Vlad Skarzhevskyy <notifications@github.com
|
And here is the code in question: if (!timestamptz) {
This does not have timezone information so the driver tries to "fix" it. Dave Dave Cramer On Sun, Mar 23, 2014 at 10:04 AM, Dave Cramer davecramer@gmail.com wrote:
|
To me this looks like the the server side problem and not driver. Can you please point me to the wire protocol specs. For me it is confusing that in toTimeBin function driver is reading timeOffset form the stream while in toTimestampBin there are no such things. Also keep in mind. |
We will try to reproduce the problem in perl. See what this will bring. |
I have a solution already I will create a PR shortly for you to test Dave Cramer On Sun, Mar 23, 2014 at 12:22 PM, Vlad Skarzhevskyy <
|
Vlad, Can you test this #133 ? At this point this works on my computer. But opens up the question: Should Dave Dave Cramer On Sun, Mar 23, 2014 at 12:40 PM, Dave Cramer davecramer@gmail.com wrote:
|
Timestamp write and read tested and it works as expected for every hour in last 5 years. |
Vlad, thanks for finding this problem and for testing it. Cheers, Dave Cramer On Sun, Mar 23, 2014 at 3:37 PM, Vlad Skarzhevskyy <notifications@github.com
|
Dave I see you reverted the changes. Also the bug still exist in latest version 9.3-1102-jdbc41. Will you be reopening the bug and we need to create a new one ? |
Vlad, Can you comment on #134 Look at the I'll do another release if we can get to the bottom of this Dave Cramer On 13 July 2014 13:38, Vlad Skarzhevskyy notifications@github.com wrote:
|
I will think about this. Will keep you posted. Please reopen the bug anyway. |
Not sure how to reopen it. I'll look at whatever you find though Dave Cramer On 13 July 2014 14:28, Vlad Skarzhevskyy notifications@github.com wrote:
|
Reopened. I've read through the thread, though I haven't run the test cases. It seems clear that the issue is with PgJDBC when using server-side prepared statements, so if you set: in your JDBC URL the issue should go away, and if you set it to 1 the problem should occur immediately, rather than requiring 5 iterations. (I think we're going to need to change the prepare threshold default to 1 in a future release; behaviour changes caused by the switch are too common despite the best efforts of everyone involved). As for what the driver is doing with the timestamp - all PostgreSQL returns for In either case the local Java runtime's time zone should have absolutely zero effect. If the local Java environment's time zone is being considered in any way that's a clear bug. |
Your test case uses
Fixing this probably requires a backward compatibility connection string option, though. |
Any news on this? I've bumped on this problem today. |
Can you provide a test case to show us what you are seeing. Most times this is just unexpected behaviour |
I've prepared a small test case without all the dependencies I'm using in my project. I've used the latest driver with PostgreSQL 9.4.5 and JDK8. package com.megothss;
import java.sql.*;
public class Main {
public static void main(String[] args) throws SQLException, ClassNotFoundException {
Class.forName("org.postgresql.Driver");
try (Connection connection = DriverManager.getConnection("jdbc:postgresql:postgres?user=postgres")) {
try (PreparedStatement pstmt = connection.prepareStatement("SELECT ?::INT4 AS attempt, CURRENT_TIMESTAMP::TIMESTAMPTZ;")) {
for (int i = 0; i < 10; i++) {
pstmt.setInt(1, i);
try (ResultSet rs = pstmt.executeQuery()) {
rs.next();
System.out.println(String.format("Attempt %d = %s", rs.getInt(1), rs.getString(2)));
}
}
}
}
}
} The following output was produced
As you can see, I've got the expect output until attempt 4. After that the timezone information is missing. I can also confirm that the |
…xt representation Note: tstz in binary is sent without timezone, thus arameterStatus(TimeZone = GMT-01:00) is used to track connection's time zone closes #130
@megothss , thanks for the test.
Are you interested finishing that PR? |
…xt representation Note: tstz in binary is sent without timezone, thus arameterStatus(TimeZone = GMT-01:00) is used to track connection's time zone closes #130
Any volunteers to check if #490 resolves "timestamp vs timezone issue"? |
Thanks, I will get the commit mentioned in #490 and will run my original tests to see if it solves the problem. |
Hi Vladimir I believe I'm missing something. the code is using the binary encoded timestamp value. When I set breakpoints there.. Any suggestions what was the change applied in 9.3-1104 release ? |
Well, 9.4-1204 includes #387. It should fix most of timestamp issues. #490 fixes just the issue mentioned in #130 (comment) |
Sorry Since the original issue is resolved the bug should be definitely closed. |
thanks for testing |
When you try to retrieve the same Timestamp multiple times on some iteration (4th ... 17th) it may return the time that is one hour off.
data type: timestamp without time zone
The problem exists only in PostgreSql when prepared statement pool is used.
e.g. I store 2014-03-09 06:21:28 but JDBC may returns 2014-03-09 07:21:28
key is "may return". See the tests.
in Eastern Time Zone
http://www.timetemperature.com/canada/daylight_saving_time_canada.shtml
(+1 hour)
Dates: DST Begins at 2 a.m.
Hours that will produce this problem 3AM, 4AM, 5AM and 6AM
(-1 hour)
DST Ends at 2 a.m.
Hours that will produce this problem 1AM, 2AM, 3AM, and 4AM
Statement pool C3P0 or DBCP2 was used during tests.
MySQL, Oracle and HSQLDB divers do not show similar problem.
Envelopment:
Oracle Java 1.7.
postgresql-9.2-1002-jdbc4.jar or postgresql-9.3-1101-jdbc41.jar
PostgreSQL 9.1.5 (Ubuntu 12.04.4 or Windows 7 )
or PostgreSQL 9.3.3 on Windows 7
Tests provided will fail in Eastern Time Zone (e.g. NY/USA)
Tests inside pgjdbc code base. (need to add C3P0 or DBCP2 jar to classpath)
https://github.com/skarzhevskyy/pgjdbc/tree/d1b89b42fbe3d214155d3eb35a00864438ddfcf1/org/postgresql/test/other
Standalone test:
https://github.com/skarzhevskyy/pgjdbc/blob/d1b89b42fbe3d214155d3eb35a00864438ddfcf1/src/postgresql-integration/src/test/java/org/postgresql/test/other/DaylightSavingJDBC.java
with maven project since dependencies required to create statement pool
https://github.com/skarzhevskyy/pgjdbc/tree/d1b89b42fbe3d214155d3eb35a00864438ddfcf1/src/postgresql-integration
The text was updated successfully, but these errors were encountered: