diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 6f92bad..da08c46 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -794,6 +794,46 @@ TransactionStartedDuringRecovery(void)
 }
 
 /*
+ *	CheckCurrentTransactionDuration
+ *
+ * Returns true if the current transaction's duration is longer than
+ * log_min_duration_transaction.
+ */
+bool
+CheckCurrentTransactionDuration(char *msec_str)
+{
+	long		secs;
+	int		usecs;
+	int		msecs;
+	bool		exceeded;
+	
+	TimestampDifference(xactStartTimestamp, 
+						xactStopTimestamp, 
+						&secs, 
+						&usecs);
+	msecs = usecs / 1000;
+
+	/*
+	 * This odd-looking test for log_min_duration_transaction being exceeded
+	 * is designed to avoid integer overflow with very long durations:
+	 * don't compute secs * 1000 until we've verified it will fit in int.
+	 */
+	exceeded = (log_min_duration_transaction == 0 ||
+				(log_min_duration_transaction > 0 &&
+				(secs > log_min_duration_transaction / 1000 ||
+				secs * 1000 + msecs >= log_min_duration_transaction)));
+	
+	if (exceeded)
+	{
+		snprintf(msec_str, 32, "%ld.%03d",
+			secs * 1000 + msecs, usecs % 1000);
+		return true;
+	}
+	return false;
+}
+
+
+/*
  *	CommandCounterIncrement
  */
 void
@@ -1007,6 +1047,7 @@ RecordTransactionCommit(void)
 	SharedInvalidationMessage *invalMessages = NULL;
 	bool		RelcacheInitFileInval = false;
 	bool		wrote_xlog;
+	char		msec_str[32];
 
 	/* Get data needed for commit record */
 	nrels = smgrGetPendingDeletes(true, &rels);
@@ -1235,6 +1276,12 @@ RecordTransactionCommit(void)
 		END_CRIT_SECTION();
 	}
 
+	/* Check whether to log the duration of the transaction */
+	if (CheckCurrentTransactionDuration(msec_str))
+		ereport(LOG,
+			(errmsg("transaction %u duration: %s ms", xid, msec_str),
+			 errhidestmt(true)));
+
 	/* Compute latestXid while we have the child XIDs handy */
 	latestXid = TransactionIdLatest(xid, nchildren, children);
 
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index aca4243..6e8cc43 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -451,6 +451,7 @@ int			log_min_error_statement = ERROR;
 int			log_min_messages = WARNING;
 int			client_min_messages = NOTICE;
 int			log_min_duration_statement = -1;
+int			log_min_duration_transaction = -1;
 int			log_temp_files = -1;
 int			trace_recovery_messages = LOG;
 
@@ -2211,6 +2212,18 @@ static struct config_int ConfigureNamesInt[] =
 	},
 
 	{
+		{"log_min_duration_transaction", PGC_SUSET, LOGGING_WHEN,
+			gettext_noop("Sets the minimum duration time above which "
+						 "transactions will be logged."),
+			gettext_noop("Zero logs all transactions. -1 turns this feature off."),
+			GUC_UNIT_MS
+		},
+		&log_min_duration_transaction,
+		-1, -1, INT_MAX,
+		NULL, NULL, NULL
+	},
+
+	{
 		{"log_autovacuum_min_duration", PGC_SIGHUP, LOGGING_WHAT,
 			gettext_noop("Sets the minimum execution time above which "
 						 "autovacuum actions will be logged."),
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index dac6776..b6ee362 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -397,6 +397,11 @@
 					# statements running at least this number
 					# of milliseconds
 
+#log_min_duration_transaction = -1	# -1 is disabled, 0 logs all transactions
+					# and their durations, > 0 logs only
+					# transactions running at least this number
+					# of milliseconds
+
 
 # - What to Log -
 
diff --git a/src/include/tcop/tcopprot.h b/src/include/tcop/tcopprot.h
index 60f7532..3a9a7b5 100644
--- a/src/include/tcop/tcopprot.h
+++ b/src/include/tcop/tcopprot.h
@@ -77,7 +77,7 @@ extern void PostgresMain(int argc, char *argv[],
 extern long get_stack_depth_rlimit(void);
 extern void ResetUsage(void);
 extern void ShowUsage(const char *title);
-extern int	check_log_duration(char *msec_str, bool was_logged);
+extern int	check_log_duration(char *msec_str, bool was_logged, bool is_statement);
 extern void set_debug_options(int debug_flag,
 				  GucContext context, GucSource source);
 extern bool set_plan_disabling_options(const char *arg,
diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h
index 66b5cd3..fe58a2e 100644
--- a/src/include/utils/guc.h
+++ b/src/include/utils/guc.h
@@ -222,6 +222,7 @@ extern int	log_min_error_statement;
 extern int	log_min_messages;
 extern int	client_min_messages;
 extern int	log_min_duration_statement;
+extern int	log_min_duration_transaction;
 extern int	log_temp_files;
 
 extern int	temp_file_limit;
