[PATCHES] pg_autovacuum fixes

2004-05-22 Thread Matthew T. O'Connor
This weekend I am trying to fix up all known the pg_autovacuum issues
that should be resolved for 7.4.3.  I am aware of only two issues:  temp
table issues, and unchecked send_query() calls, if I am forgetting
something, please let me know.

1) temp table issue:  
I was not able to reproduce the crash associated with temp tables.  I
spent a while creating tables doing updates and dropping them trying
without success to get pg_autovacuum to crash.  Since I couldn't trigger
the problem, I will need someone else to test to see if I have fixed the
problem.  Anyway, I have modified the query to exclude temp tables from
the list of tables to work with.  So we should no longer be dealing with
temp tables at all which should side step any temp table related problem
we might have been having.

2) Unchecked send_query() function calls:
As best as I can tell, this is mostly a non-issue, but I went ahead
added a check to any section that did anything with the result of
send_query, so if this was an issue, it should be fixed now.  BTW, this
might have been the cause of the temp table related crash, but that is
just a guess.


Matthew O'Connor


*** ./pg_autovacuum.c.orig	2004-05-22 02:56:09.0 -0400
--- ./pg_autovacuum.c	2004-05-22 03:36:01.152691850 -0400
***
*** 225,294 
  		 * tables to the list that are new
  		 */
  		res = send_query((char *) TABLE_STATS_QUERY, dbi);
! 		t = PQntuples(res);
! 
! 		/*
! 		 * First: use the tbl_list as the outer loop and the result set as
! 		 * the inner loop, this will determine what tables should be
! 		 * removed
! 		 */
! 		while (tbl_elem != NULL)
! 		{
! 			tbl = ((tbl_info *) DLE_VAL(tbl_elem));
! 			found_match = 0;
! 
! 			for (i = 0; i  t; i++)
! 			{	/* loop through result set looking for a
!  * match */
! if (tbl-relid == atooid(PQgetvalue(res, i, PQfnumber(res, oid
! {
! 	found_match = 1;
! 	break;
! }
! 			}
! 			if (found_match == 0)
! 			{	/* then we didn't find this tbl_elem in
!  * the result set */
! Dlelem	   *elem_to_remove = tbl_elem;
! 
! tbl_elem = DLGetSucc(tbl_elem);
! remove_table_from_list(elem_to_remove);
! 			}
! 			else
! tbl_elem = DLGetSucc(tbl_elem);
! 		}		/* Done removing dropped tables from the
!  * table_list */
! 
! 		/*
! 		 * Then loop use result set as outer loop and tbl_list as the
! 		 * inner loop to determine what tables are new
! 		 */
! 		for (i = 0; i  t; i++)
  		{
! 			tbl_elem = DLGetHead(dbi-table_list);
! 			found_match = 0;
  			while (tbl_elem != NULL)
  			{
  tbl = ((tbl_info *) DLE_VAL(tbl_elem));
! if (tbl-relid == atooid(PQgetvalue(res, i, PQfnumber(res, oid
! {
! 	found_match = 1;
! 	break;
  }
! tbl_elem = DLGetSucc(tbl_elem);
! 			}
! 			if (found_match == 0)		/* then we didn't find this result
! 		 * now in the tbl_list */
  			{
! DLAddTail(dbi-table_list, DLNewElem(init_table_info(res, i, dbi)));
! if (args-debug = 1)
  {
! 	sprintf(logbuffer, added table: %s.%s, dbi-dbname,
! 			((tbl_info *) DLE_VAL(DLGetTail(dbi-table_list)))-table_name);
! 	log_entry(logbuffer);
  }
! 			}
! 		}		/* end of for loop that adds tables */
  		fflush(LOGOUTPUT);
  		PQclear(res);
  		res = NULL;
--- 225,297 
  		 * tables to the list that are new
  		 */
  		res = send_query((char *) TABLE_STATS_QUERY, dbi);
! 		if (res != NULL)
  		{
! 			t = PQntuples(res);
! 			
! 			/*
! 			* First: use the tbl_list as the outer loop and the result set as
! 			* the inner loop, this will determine what tables should be
! 			* removed
! 			*/
  			while (tbl_elem != NULL)
  			{
  tbl = ((tbl_info *) DLE_VAL(tbl_elem));
! found_match = 0;
! 
! for (i = 0; i  t; i++)
! {	/* loop through result set looking for a
! 	* match */
! 	if (tbl-relid == atooid(PQgetvalue(res, i, PQfnumber(res, oid
! 	{
! 		found_match = 1;
! 		break;
! 	}
  }
! if (found_match == 0)
! {	/* then we didn't find this tbl_elem in
! 	* the result set */
! 	Dlelem	   *elem_to_remove = tbl_elem;
! 	
! 	tbl_elem = DLGetSucc(tbl_elem);
! 	remove_table_from_list(elem_to_remove);
! }
! else
! 	tbl_elem = DLGetSucc(tbl_elem);
! 			}		/* Done removing dropped tables from the
! 	* table_list */
! 			
! 			/*
! 			* Then loop use result set as outer loop and tbl_list as the
! 			* inner loop to determine what tables are new
! 			*/
! 			for (i = 0; i  t; i++)
  			{
! tbl_elem = DLGetHead(dbi-table_list);
! found_match = 0;
! while (tbl_elem != NULL)
  {
! 	tbl = ((tbl_info *) DLE_VAL(tbl_elem));
! 	if (tbl-relid == atooid(PQgetvalue(res, i, PQfnumber(res, oid
! 	{
! 		found_match = 1;
! 		break;
! 	}
! 	tbl_elem = DLGetSucc(tbl_elem);
  }
! if (found_match == 0)		/* then we didn't find this result
! 			* now in the tbl_list */
! 

Re: [PATCHES] Cancel/Kill backend functions

2004-05-22 Thread Neil Conway
Magnus Hagander wrote:
Per previous discussions, here are two functions to send INT and TERM
signals to other backends.They permit only INT and TERM, and permits
sending only to postgresql backends (as registered in pgstat).
Why does this depend on pgstat? ISTM it would be better to use the 
per-backend PGPROC information, which is stored in shared memory. 
Consider TransactionIdIsInProgress() for an example.

-Neil
---(end of broadcast)---
TIP 9: the planner will ignore your desire to choose an index scan if your
 joining column's datatypes do not match