From 2f8a60a094758945dda3823ede63a972ea74c78f Mon Sep 17 00:00:00 2001 From: Pavan Deolasee Date: Tue, 18 Oct 2016 10:48:39 +0530 Subject: [PATCH] Use OS timestamp for computing if the current statement has taken more than 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 | 10 ++++++++++ src/backend/tcop/postgres.c | 6 +++++- src/include/access/xact.h | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 2a14c3cc1b..d2e9aea110 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -929,6 +929,16 @@ GetCurrentStatementStartTimestamp(void) #endif } +#ifdef XCP +/* + * GetCurrentLocalStatementStartTimestamp + */ +TimestampTz +GetCurrentLocalStatementStartTimestamp(void) +{ + return stmtStartTimestamp; +} +#endif /* * GetCurrentTransactionStopTimestamp * diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 6e14fea97c..0d6685963e 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -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; diff --git a/src/include/access/xact.h b/src/include/access/xact.h index 5181082f26..a8133c73f7 100644 --- a/src/include/access/xact.h +++ b/src/include/access/xact.h @@ -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 -- 2.39.5