Print proper cause of statement cancel, user interaction or timeout.
authorBruce Momjian <bruce@momjian.us>
Mon, 19 Sep 2005 17:21:49 +0000 (17:21 +0000)
committerBruce Momjian <bruce@momjian.us>
Mon, 19 Sep 2005 17:21:49 +0000 (17:21 +0000)
doc/src/sgml/config.sgml
src/backend/storage/lmgr/proc.c
src/backend/tcop/postgres.c
src/include/storage/proc.h
src/test/regress/expected/prepared_xacts.out

index dd784ee335fc220673821959d6ec9e0787134944..cfbac049499d719e71b11cc34ed966f862feba57 100644 (file)
@@ -3232,7 +3232,10 @@ SELECT * FROM parent WHERE key = 2400;
       <listitem>
        <para>
         Abort any statement that takes over the specified number of
-        milliseconds.  A value of zero (the default) turns off the limitation.
+        milliseconds.  If <varname>log_min_error_statement</> is set to
+        <literal>ERROR</> or lower, the statement that timed out will also be
+        logged.  A value of zero (the default) turns off the 
+        limitation.
        </para>
       </listitem>
      </varlistentry>
index 0b28b9301560295e834bedf23615588dd3dcfeb6..89e667c0b8dd80a3c55313e3f67ef983a7ed296a 100644 (file)
@@ -78,6 +78,7 @@ static bool waitingForLock = false;
 /* Mark these volatile because they can be changed by signal handler */
 static volatile bool statement_timeout_active = false;
 static volatile bool deadlock_timeout_active = false;
+volatile bool cancel_from_timeout = false;
 
 /* statement_fin_time is valid only if statement_timeout_active is true */
 static struct timeval statement_fin_time;
@@ -1058,6 +1059,7 @@ enable_sig_alarm(int delayms, bool is_statement_timeout)
                Assert(!deadlock_timeout_active);
                statement_fin_time = fin_time;
                statement_timeout_active = true;
+               cancel_from_timeout = false;
        }
        else if (statement_timeout_active)
        {
@@ -1128,14 +1130,18 @@ disable_sig_alarm(bool is_statement_timeout)
                MemSet(&timeval, 0, sizeof(struct itimerval));
                if (setitimer(ITIMER_REAL, &timeval, NULL))
                {
-                       statement_timeout_active = deadlock_timeout_active = false;
+                       statement_timeout_active = false;
+                       cancel_from_timeout = false;
+                       deadlock_timeout_active = false;
                        return false;
                }
 #else
                /* BeOS doesn't have setitimer, but has set_alarm */
                if (set_alarm(B_INFINITE_TIMEOUT, B_PERIODIC_ALARM) < 0)
                {
-                       statement_timeout_active = deadlock_timeout_active = false;
+                       statement_timeout_active = false;
+                       cancel_from_timeout = false;
+                       deadlock_timeout_active = false;
                        return false;
                }
 #endif
@@ -1146,7 +1152,10 @@ disable_sig_alarm(bool is_statement_timeout)
 
        /* Cancel or reschedule statement timeout */
        if (is_statement_timeout)
+       {
                statement_timeout_active = false;
+               cancel_from_timeout = false;
+       }
        else if (statement_timeout_active)
        {
                if (!CheckStatementTimeout())
@@ -1179,6 +1188,7 @@ CheckStatementTimeout(void)
        {
                /* Time to die */
                statement_timeout_active = false;
+               cancel_from_timeout = true;
                kill(MyProcPid, SIGINT);
        }
        else
index 21ae7be42b2cf7b77180dae5c94d52d50b931e11..f2c0fc6ffb6b24fd579a3bd627898bb55c2684af 100644 (file)
@@ -1979,7 +1979,9 @@ start_xact_command(void)
                /* Set statement timeout running, if any */
                if (StatementTimeout > 0)
                        enable_sig_alarm(StatementTimeout, true);
-
+               else
+                       cancel_from_timeout = false;
+               
                xact_started = true;
        }
 }
@@ -2203,9 +2205,14 @@ ProcessInterrupts(void)
                ImmediateInterruptOK = false;   /* not idle anymore */
                DisableNotifyInterrupt();
                DisableCatchupInterrupt();
-               ereport(ERROR,
-                               (errcode(ERRCODE_QUERY_CANCELED),
-                                errmsg("canceling query due to user request or statement timeout")));
+               if (cancel_from_timeout)
+                       ereport(ERROR,
+                                       (errcode(ERRCODE_QUERY_CANCELED),
+                                        errmsg("canceling statement due to statement timeout")));
+               else
+                       ereport(ERROR,
+                                       (errcode(ERRCODE_QUERY_CANCELED),
+                                        errmsg("canceling statement due to user request")));
        }
        /* If we get here, do nothing (probably, QueryCancelPending was reset) */
 }
index 1ebd77b94f1d44b0ea73de510de86795ac340929..28b14c18683c7adb15c33b6b0978b04b78c8824d 100644 (file)
@@ -117,6 +117,8 @@ typedef struct PROC_HDR
 extern int     DeadlockTimeout;
 extern int     StatementTimeout;
 
+extern volatile bool cancel_from_timeout;
+
 
 /*
  * Function Prototypes
index f36d1a2428ce0338021d665e6aa6084871c2f11a..aa4d22e8b7e45937774dbc38bd62d9a5e50b4231 100644 (file)
@@ -159,7 +159,7 @@ SELECT gid FROM pg_prepared_xacts;
 -- pxtest3 should be locked because of the pending DROP
 set statement_timeout to 1000;
 SELECT * FROM pxtest3;
-ERROR:  canceling query due to user request or statement timeout
+ERROR:  canceling statement due to statement timeout
 reset statement_timeout;
 -- Disconnect, we will continue testing in a different backend
 \c -
@@ -174,7 +174,7 @@ SELECT gid FROM pg_prepared_xacts;
 -- pxtest3 should still be locked because of the pending DROP
 set statement_timeout to 1000;
 SELECT * FROM pxtest3;
-ERROR:  canceling query due to user request or statement timeout
+ERROR:  canceling statement due to statement timeout
 reset statement_timeout;
 -- Commit table creation
 COMMIT PREPARED 'regress-one';