patch for pg_autovacuum

Started by Brian Hirtabout 22 years ago1 messages
#1Brian Hirt
bhirt@mobygames.com
1 attachment(s)

here's a patch that joins on pg_class.oid instead of
pg_class.relfilenode, also i have renamed the table structure from
relfilenode to relid.

Attachments:

patchapplication/octet-stream; name=patch; x-unix-mode=0644Download
diff --context ./pg_autovacuum.c ../pg_autovacuum.fix/pg_autovacuum.c
*** ./pg_autovacuum.c	2003-10-10 13:26:25.000000000 -0600
--- ../pg_autovacuum.fix/pg_autovacuum.c	2003-11-24 12:41:24.000000000 -0700
***************
*** 116,122 ****
  		 atol(PQgetvalue(res, row, PQfnumber(res, "n_tup_upd"))));
  	new_tbl->curr_vacuum_count = new_tbl->CountAtLastVacuum;
  
! 	new_tbl->relfilenode = atoi(PQgetvalue(res, row, PQfnumber(res, "relfilenode")));
  	new_tbl->reltuples = atoi(PQgetvalue(res, row, PQfnumber(res, "reltuples")));
  	new_tbl->relpages = atoi(PQgetvalue(res, row, PQfnumber(res, "relpages")));
  
--- 116,122 ----
  		 atol(PQgetvalue(res, row, PQfnumber(res, "n_tup_upd"))));
  	new_tbl->curr_vacuum_count = new_tbl->CountAtLastVacuum;
  
! 	new_tbl->relid = atoi(PQgetvalue(res, row, PQfnumber(res, "oid")));
  	new_tbl->reltuples = atoi(PQgetvalue(res, row, PQfnumber(res, "reltuples")));
  	new_tbl->relpages = atoi(PQgetvalue(res, row, PQfnumber(res, "relpages")));
  
***************
*** 154,160 ****
  
  	if (dbi->conn != NULL)
  	{
! 		snprintf(query, sizeof(query), PAGES_QUERY, tbl->relfilenode);
  		res = send_query(query, dbi);
  		if (res != NULL)
  		{
--- 154,160 ----
  
  	if (dbi->conn != NULL)
  	{
! 		snprintf(query, sizeof(query), PAGES_QUERY, tbl->relid);
  		res = send_query(query, dbi);
  		if (res != NULL)
  		{
***************
*** 237,243 ****
  			for (i = 0; i < t; i++)
  			{					/* loop through result set looking for a
  								 * match */
! 				if (tbl->relfilenode == atoi(PQgetvalue(res, i, PQfnumber(res, "relfilenode"))))
  				{
  					found_match = 1;
  					break;
--- 237,243 ----
  			for (i = 0; i < t; i++)
  			{					/* loop through result set looking for a
  								 * match */
! 				if (tbl->relid == atoi(PQgetvalue(res, i, PQfnumber(res, "oid"))))
  				{
  					found_match = 1;
  					break;
***************
*** 267,273 ****
  			while (tbl_elem != NULL)
  			{
  				tbl = ((tbl_info *) DLE_VAL(tbl_elem));
! 				if (tbl->relfilenode == atoi(PQgetvalue(res, i, PQfnumber(res, "relfilenode"))))
  				{
  					found_match = 1;
  					break;
--- 267,273 ----
  			while (tbl_elem != NULL)
  			{
  				tbl = ((tbl_info *) DLE_VAL(tbl_elem));
! 				if (tbl->relid == atoi(PQgetvalue(res, i, PQfnumber(res, "oid"))))
  				{
  					found_match = 1;
  					break;
***************
*** 361,367 ****
  {
  	sprintf(logbuffer, "  table name:     %s.%s", tbl->dbi->dbname, tbl->table_name);
  	log_entry(logbuffer);
! 	sprintf(logbuffer, "     relfilenode: %i;   relisshared: %i", tbl->relfilenode, tbl->relisshared);
  	log_entry(logbuffer);
  	sprintf(logbuffer, "     reltuples: %i;  relpages: %i", tbl->reltuples, tbl->relpages);
  	log_entry(logbuffer);
--- 361,367 ----
  {
  	sprintf(logbuffer, "  table name:     %s.%s", tbl->dbi->dbname, tbl->table_name);
  	log_entry(logbuffer);
! 	sprintf(logbuffer, "     relid: %i;   relisshared: %i", tbl->relid, tbl->relisshared);
  	log_entry(logbuffer);
  	sprintf(logbuffer, "     reltuples: %i;  relpages: %i", tbl->reltuples, tbl->relpages);
  	log_entry(logbuffer);
***************
*** 1067,1073 ****
  						{		/* Loop through tables in list */
  							tbl = ((tbl_info *) DLE_VAL(tbl_elem));		/* set tbl_info =
  																		 * current_table */
! 							if (tbl->relfilenode == atoi(PQgetvalue(res, j, PQfnumber(res, "relfilenode"))))
  							{
  								tbl->curr_analyze_count =
  									(atol(PQgetvalue(res, j, PQfnumber(res, "n_tup_ins"))) +
--- 1067,1073 ----
  						{		/* Loop through tables in list */
  							tbl = ((tbl_info *) DLE_VAL(tbl_elem));		/* set tbl_info =
  																		 * current_table */
! 							if (tbl->relid == atoi(PQgetvalue(res, j, PQfnumber(res, "oid"))))
  							{
  								tbl->curr_analyze_count =
  									(atol(PQgetvalue(res, j, PQfnumber(res, "n_tup_ins"))) +
diff --context ./pg_autovacuum.h ../pg_autovacuum.fix/pg_autovacuum.h
*** ./pg_autovacuum.h	2003-09-13 10:26:18.000000000 -0600
--- ../pg_autovacuum.fix/pg_autovacuum.h	2003-11-24 12:40:33.000000000 -0700
***************
*** 34,43 ****
  #define VACUUM_ANALYZE		0
  #define ANALYZE_ONLY		1
  
! #define TABLE_STATS_QUERY	"select a.relfilenode,a.relname,a.relnamespace,a.relpages,a.relisshared,a.reltuples,b.schemaname,b.n_tup_ins,b.n_tup_upd,b.n_tup_del from pg_class a, pg_stat_all_tables b where a.relfilenode=b.relid and a.relkind = 'r'"
  
  #define FRONTEND
! #define PAGES_QUERY "select relfilenode,reltuples,relpages from pg_class where relfilenode=%i"
  #define FROZENOID_QUERY "select oid,age(datfrozenxid) from pg_database where datname = 'template1'"
  #define FROZENOID_QUERY2 "select oid,datname,age(datfrozenxid) from pg_database where datname!='template0'"
  
--- 34,43 ----
  #define VACUUM_ANALYZE		0
  #define ANALYZE_ONLY		1
  
! #define TABLE_STATS_QUERY	"select a.oid,a.relname,a.relnamespace,a.relpages,a.relisshared,a.reltuples,b.schemaname,b.n_tup_ins,b.n_tup_upd,b.n_tup_del from pg_class a, pg_stat_all_tables b where a.oid=b.relid and a.relkind = 'r'"
  
  #define FRONTEND
! #define PAGES_QUERY "select oid,reltuples,relpages from pg_class where oid=%i"
  #define FROZENOID_QUERY "select oid,age(datfrozenxid) from pg_database where datname = 'template1'"
  #define FROZENOID_QUERY2 "select oid,datname,age(datfrozenxid) from pg_database where datname!='template0'"
  
***************
*** 84,90 ****
  {
  	char	   *schema_name,
  			   *table_name;
! 	int			relfilenode,
  				reltuples,
  				relisshared,
  				relpages;
--- 84,90 ----
  {
  	char	   *schema_name,
  			   *table_name;
! 	int			relid,
  				reltuples,
  				relisshared,
  				relpages;