Skip to content

Commit 6586571

Browse files
committed
Print proper cause of statement cancel, user interaction or timeout.
1 parent 591a29b commit 6586571

File tree

5 files changed

+35
-13
lines changed

5 files changed

+35
-13
lines changed

doc/src/sgml/config.sgml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.17 2005/09/13 15:24:56 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.18 2005/09/19 17:21:46 momjian Exp $
33
-->
44
<chapter Id="runtime-config">
55
<title>Run-time Configuration</title>
@@ -3232,7 +3232,10 @@ SELECT * FROM parent WHERE key = 2400;
32323232
<listitem>
32333233
<para>
32343234
Abort any statement that takes over the specified number of
3235-
milliseconds. A value of zero (the default) turns off the limitation.
3235+
milliseconds. If <varname>log_min_error_statement</> is set to
3236+
<literal>ERROR</> or lower, the statement that timed out will also be
3237+
logged. A value of zero (the default) turns off the
3238+
limitation.
32363239
</para>
32373240
</listitem>
32383241
</varlistentry>

src/backend/storage/lmgr/proc.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.163 2005/08/20 23:26:24 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.164 2005/09/19 17:21:47 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -78,6 +78,7 @@ static bool waitingForLock = false;
7878
/* Mark these volatile because they can be changed by signal handler */
7979
static volatile bool statement_timeout_active = false;
8080
static volatile bool deadlock_timeout_active = false;
81+
volatile bool cancel_from_timeout = false;
8182

8283
/* statement_fin_time is valid only if statement_timeout_active is true */
8384
static struct timeval statement_fin_time;
@@ -1058,6 +1059,7 @@ enable_sig_alarm(int delayms, bool is_statement_timeout)
10581059
Assert(!deadlock_timeout_active);
10591060
statement_fin_time = fin_time;
10601061
statement_timeout_active = true;
1062+
cancel_from_timeout = false;
10611063
}
10621064
else if (statement_timeout_active)
10631065
{
@@ -1128,14 +1130,18 @@ disable_sig_alarm(bool is_statement_timeout)
11281130
MemSet(&timeval, 0, sizeof(struct itimerval));
11291131
if (setitimer(ITIMER_REAL, &timeval, NULL))
11301132
{
1131-
statement_timeout_active = deadlock_timeout_active = false;
1133+
statement_timeout_active = false;
1134+
cancel_from_timeout = false;
1135+
deadlock_timeout_active = false;
11321136
return false;
11331137
}
11341138
#else
11351139
/* BeOS doesn't have setitimer, but has set_alarm */
11361140
if (set_alarm(B_INFINITE_TIMEOUT, B_PERIODIC_ALARM) < 0)
11371141
{
1138-
statement_timeout_active = deadlock_timeout_active = false;
1142+
statement_timeout_active = false;
1143+
cancel_from_timeout = false;
1144+
deadlock_timeout_active = false;
11391145
return false;
11401146
}
11411147
#endif
@@ -1146,7 +1152,10 @@ disable_sig_alarm(bool is_statement_timeout)
11461152

11471153
/* Cancel or reschedule statement timeout */
11481154
if (is_statement_timeout)
1155+
{
11491156
statement_timeout_active = false;
1157+
cancel_from_timeout = false;
1158+
}
11501159
else if (statement_timeout_active)
11511160
{
11521161
if (!CheckStatementTimeout())
@@ -1179,6 +1188,7 @@ CheckStatementTimeout(void)
11791188
{
11801189
/* Time to die */
11811190
statement_timeout_active = false;
1191+
cancel_from_timeout = true;
11821192
kill(MyProcPid, SIGINT);
11831193
}
11841194
else

src/backend/tcop/postgres.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.459 2005/09/16 19:31:04 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.460 2005/09/19 17:21:47 momjian Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -1979,7 +1979,9 @@ start_xact_command(void)
19791979
/* Set statement timeout running, if any */
19801980
if (StatementTimeout > 0)
19811981
enable_sig_alarm(StatementTimeout, true);
1982-
1982+
else
1983+
cancel_from_timeout = false;
1984+
19831985
xact_started = true;
19841986
}
19851987
}
@@ -2203,9 +2205,14 @@ ProcessInterrupts(void)
22032205
ImmediateInterruptOK = false; /* not idle anymore */
22042206
DisableNotifyInterrupt();
22052207
DisableCatchupInterrupt();
2206-
ereport(ERROR,
2207-
(errcode(ERRCODE_QUERY_CANCELED),
2208-
errmsg("canceling query due to user request or statement timeout")));
2208+
if (cancel_from_timeout)
2209+
ereport(ERROR,
2210+
(errcode(ERRCODE_QUERY_CANCELED),
2211+
errmsg("canceling statement due to statement timeout")));
2212+
else
2213+
ereport(ERROR,
2214+
(errcode(ERRCODE_QUERY_CANCELED),
2215+
errmsg("canceling statement due to user request")));
22092216
}
22102217
/* If we get here, do nothing (probably, QueryCancelPending was reset) */
22112218
}

src/include/storage/proc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.81 2005/08/20 23:26:34 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.82 2005/09/19 17:21:48 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -117,6 +117,8 @@ typedef struct PROC_HDR
117117
extern int DeadlockTimeout;
118118
extern int StatementTimeout;
119119

120+
extern volatile bool cancel_from_timeout;
121+
120122

121123
/*
122124
* Function Prototypes

src/test/regress/expected/prepared_xacts.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ SELECT gid FROM pg_prepared_xacts;
159159
-- pxtest3 should be locked because of the pending DROP
160160
set statement_timeout to 1000;
161161
SELECT * FROM pxtest3;
162-
ERROR: canceling query due to user request or statement timeout
162+
ERROR: canceling statement due to statement timeout
163163
reset statement_timeout;
164164
-- Disconnect, we will continue testing in a different backend
165165
\c -
@@ -174,7 +174,7 @@ SELECT gid FROM pg_prepared_xacts;
174174
-- pxtest3 should still be locked because of the pending DROP
175175
set statement_timeout to 1000;
176176
SELECT * FROM pxtest3;
177-
ERROR: canceling query due to user request or statement timeout
177+
ERROR: canceling statement due to statement timeout
178178
reset statement_timeout;
179179
-- Commit table creation
180180
COMMIT PREPARED 'regress-one';

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy