Fix problems in pg_autovacuum:

1) temp table crash

2) Check send_query() function call return value.

Backpatch to 7.4.X.
This commit is contained in:
Bruce Momjian 2004-05-26 18:48:25 +00:00
parent 1cf9d7bd24
commit b5cf1b6a21
2 changed files with 217 additions and 200 deletions

View File

@ -225,6 +225,8 @@ update_table_list(db_info * dbi)
* tables to the list that are new
*/
res = send_query((char *) TABLE_STATS_QUERY, dbi);
if (res != NULL)
{
t = PQntuples(res);
/*
@ -289,6 +291,7 @@ update_table_list(db_info * dbi)
}
}
} /* end of for loop that adds tables */
}
fflush(LOGOUTPUT);
PQclear(res);
res = NULL;
@ -410,6 +413,8 @@ init_db_list()
if (dbs->conn != NULL)
{
res = send_query(FROZENOID_QUERY, dbs);
if (res != NULL)
{
dbs->oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "oid")));
dbs->age = atol(PQgetvalue(res, 0, PQfnumber(res, "age")));
if (res)
@ -418,6 +423,9 @@ init_db_list()
if (args->debug >= 2)
print_db_list(db_list, 0);
}
else
return NULL;
}
return db_list;
}
@ -488,6 +496,8 @@ update_db_list(Dllist *db_list)
* add databases to the list that are new
*/
res = send_query(FROZENOID_QUERY2, dbi_template1);
if (res != NULL)
{
t = PQntuples(res);
/*
@ -560,6 +570,7 @@ update_db_list(Dllist *db_list)
}
}
} /* end of for loop that adds tables */
}
fflush(LOGOUTPUT);
PQclear(res);
res = NULL;
@ -599,7 +610,10 @@ xid_wraparound_check(db_info * dbi)
res = send_query("VACUUM", dbi);
/* FIXME: Perhaps should add a check for PQ_COMMAND_OK */
if (res != NULL)
{
PQclear(res);
}
return 1;
}
return 0;
@ -750,7 +764,7 @@ check_stats_enabled(db_info * dbi)
int ret = 0;
res = send_query("SHOW stats_row_level", dbi);
if (res)
if (res != NULL)
{
ret = strcmp("on", PQgetvalue(res, 0, PQfnumber(res, "stats_row_level")));
PQclear(res);
@ -1079,6 +1093,8 @@ main(int argc, char *argv[])
res = send_query(TABLE_STATS_QUERY, dbs); /* Get an updated
* snapshot of this dbs
* table stats */
if (res != NULL)
{
for (j = 0; j < PQntuples(res); j++)
{ /* loop through result set */
tbl_elem = DLGetHead(dbs->table_list); /* Reset tbl_elem to top
@ -1154,6 +1170,7 @@ main(int argc, char *argv[])
} /* end for table while loop */
} /* end for j loop (tuples in PGresult) */
} /* end if (res != NULL) */
} /* close of if(xid_wraparound_check()) */
/* Done working on this db, Clean up, then advance cur_db */
PQclear(res);

View File

@ -34,7 +34,7 @@
#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 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' and schemaname not like 'pg_temp_%'"
#define FRONTEND
#define PAGES_QUERY "select oid,reltuples,relpages from pg_class where oid=%u"