On Thu, Mar 19, 2015 at 04:36:38PM -0400, Robert Haas wrote:
> On Thu, Mar 19, 2015 at 10:23 AM, Bruce Momjian <br...@momjian.us> wrote:
> > First attached patch is more surgical and clears a possible cancel
> > request before we report the query duration in the logs --- this doesn't
> > affect any after triggers that might include CHECK_FOR_INTERRUPTS()
> > calls we want to honor.
> >
> > Another approach would be to have CommitTransaction() clear any pending
> > cancel before it calls RESUME_INTERRUPTS().  The second attached patch
> > takes that approach, and also works.
> 
> So, either way, what happens if the query cancel shows up just an
> instant after you clear the flag?

Oh, good point.  This version handles that case addressing only the
log_duration* block.

-- 
  Bruce Momjian  <br...@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
new file mode 100644
index 33720e8..4374fb4
*** a/src/backend/tcop/postgres.c
--- b/src/backend/tcop/postgres.c
*************** exec_simple_query(const char *query_stri
*** 1165,1184 ****
  	/*
  	 * Emit duration logging if appropriate.
  	 */
- 	switch (check_log_duration(msec_str, was_logged))
  	{
! 		case 1:
! 			ereport(LOG,
! 					(errmsg("duration: %s ms", msec_str),
! 					 errhidestmt(true)));
! 			break;
! 		case 2:
! 			ereport(LOG,
! 					(errmsg("duration: %s ms  statement: %s",
! 							msec_str, query_string),
! 					 errhidestmt(true),
! 					 errdetail_execute(parsetree_list)));
! 			break;
  	}
  
  	if (save_log_statement_stats)
--- 1165,1193 ----
  	/*
  	 * Emit duration logging if appropriate.
  	 */
  	{
! 		int output_duration_level = check_log_duration(msec_str, was_logged);
! 
! 		if (output_duration_level != 0)
! 		{
! 			/* hold client cancel as we have already committed */
! 			HOLD_CANCEL_INTERRUPTS();
! 
! 			if (output_duration_level == 1)
! 				ereport(LOG,
! 						(errmsg("duration: %s ms", msec_str),
! 						 errhidestmt(true)));
! 			else if (output_duration_level == 2)
! 				ereport(LOG,
! 						(errmsg("duration: %s ms  statement: %s",
! 								msec_str, query_string),
! 						 errhidestmt(true),
! 						 errdetail_execute(parsetree_list)));
! 
! 			/* clear client cancel */
! 			QueryCancelPending = false;
! 			RESUME_CANCEL_INTERRUPTS();
! 		}
  	}
  
  	if (save_log_statement_stats)
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to