Use OS timestamp for computing if the current statement has taken more than
authorPavan Deolasee <[email protected]>
Tue, 18 Oct 2016 05:18:39 +0000 (10:48 +0530)
committerPavan Deolasee <[email protected]>
Tue, 18 Oct 2016 10:07:49 +0000 (15:37 +0530)
log_min_statement_duration for execution

Since we compare the statement start time with the one obtained by
GetCurrentTimestamp(), which returns OS time without any adjustments for clock
skew, it seems fair to use statement start time obtained by the same clock.

src/backend/access/transam/xact.c
src/backend/tcop/postgres.c
src/include/access/xact.h

index 0a9fdec132eac91db9968704640164a130caa1f1..3cbe81bf7f9f47c543daf83ec6159b5098c05e20 100644 (file)
@@ -929,6 +929,16 @@ GetCurrentStatementStartTimestamp(void)
 #endif
 }
 
+#ifdef XCP
+/*
+ *     GetCurrentLocalStatementStartTimestamp
+ */
+TimestampTz
+GetCurrentLocalStatementStartTimestamp(void)
+{
+       return stmtStartTimestamp;
+}
+#endif
 /*
  *     GetCurrentTransactionStopTimestamp
  *
index 03d2509a3fb2e3af910df06b9ccf724a35feedb4..31283cc6892defc7f4e3df27a23e5b034ae18cdc 100644 (file)
@@ -2539,7 +2539,11 @@ check_log_duration(char *msec_str, bool was_logged)
                int                     msecs;
                bool            exceeded;
 
-               TimestampDifference(GetCurrentStatementStartTimestamp(),
+               /*
+                * Since GetCurrentTimestamp() returns OS time, use local time for
+                * statement-start for accurate comparison
+                */
+               TimestampDifference(GetCurrentLocalStatementStartTimestamp(),
                                                        GetCurrentTimestamp(),
                                                        &secs, &usecs);
                msecs = usecs / 1000;
index 5181082f263d4940381e1174a6e5439103180148..a8133c73f7d69c18d9d8c8aa6c9858215c8245c4 100644 (file)
@@ -341,6 +341,9 @@ extern bool SubTransactionIsActive(SubTransactionId subxid);
 extern CommandId GetCurrentCommandId(bool used);
 extern TimestampTz GetCurrentTransactionStartTimestamp(void);
 extern TimestampTz GetCurrentStatementStartTimestamp(void);
+#ifdef XCP
+extern TimestampTz GetCurrentLocalStatementStartTimestamp(void);
+#endif
 extern TimestampTz GetCurrentTransactionStopTimestamp(void);
 extern void SetCurrentStatementStartTimestamp(void);
 #ifdef PGXC