Extract catalog info for error reporting before an error actually happens.

Also, remove redundant reset of for-wraparound PGPROC flag.

Thanks to Tom Lane for noticing both bogosities.
This commit is contained in:
Alvaro Herrera 2007-10-25 14:45:55 +00:00
parent fcc20bd4ba
commit dbe48765cd
1 changed files with 18 additions and 15 deletions

View File

@ -55,7 +55,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.63 2007/10/24 20:55:36 alvherre Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.64 2007/10/25 14:45:55 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -1994,6 +1994,9 @@ do_autovacuum(void)
autovac_table *tab; autovac_table *tab;
WorkerInfo worker; WorkerInfo worker;
bool skipit; bool skipit;
char *datname,
*nspname,
*relname;
CHECK_FOR_INTERRUPTS(); CHECK_FOR_INTERRUPTS();
@ -2094,6 +2097,17 @@ next_worker:
LWLockRelease(ProcArrayLock); LWLockRelease(ProcArrayLock);
} }
/*
* Save the relation name for a possible error message, to avoid a
* catalog lookup in case of an error. We do it in
* TopTransactionContext so that they go away automatically in the next
* iteration.
*/
MemoryContextSwitchTo(TopTransactionContext);
datname = get_database_name(MyDatabaseId);
nspname = get_namespace_name(get_rel_namespace(tab->at_relid));
relname = get_rel_name(tab->at_relid);
/* /*
* We will abort vacuuming the current table if something errors out, * We will abort vacuuming the current table if something errors out,
* and continue with the next one in schedule; in particular, this * and continue with the next one in schedule; in particular, this
@ -2102,7 +2116,6 @@ next_worker:
PG_TRY(); PG_TRY();
{ {
/* have at it */ /* have at it */
MemoryContextSwitchTo(TopTransactionContext);
autovacuum_do_vac_analyze(tab->at_relid, autovacuum_do_vac_analyze(tab->at_relid,
tab->at_dovacuum, tab->at_dovacuum,
tab->at_doanalyze, tab->at_doanalyze,
@ -2118,14 +2131,10 @@ next_worker:
HOLD_INTERRUPTS(); HOLD_INTERRUPTS();
if (tab->at_dovacuum) if (tab->at_dovacuum)
errcontext("automatic vacuum of table \"%s.%s.%s\"", errcontext("automatic vacuum of table \"%s.%s.%s\"",
get_database_name(MyDatabaseId), datname, nspname, relname);
get_namespace_name(get_rel_namespace(tab->at_relid)),
get_rel_name(tab->at_relid));
else else
errcontext("automatic analyze of table \"%s.%s.%s\"", errcontext("automatic analyze of table \"%s.%s.%s\"",
get_database_name(MyDatabaseId), datname, nspname, relname);
get_namespace_name(get_rel_namespace(tab->at_relid)),
get_rel_name(tab->at_relid));
EmitErrorReport(); EmitErrorReport();
/* this resets the PGPROC flags too */ /* this resets the PGPROC flags too */
@ -2139,13 +2148,7 @@ next_worker:
} }
PG_END_TRY(); PG_END_TRY();
/* reset my PGPROC flag */ /* the PGPROC flags are reset at the next end of transaction */
if (tab->at_wraparound)
{
LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
MyProc->vacuumFlags &= ~PROC_VACUUM_FOR_WRAPAROUND;
LWLockRelease(ProcArrayLock);
}
/* be tidy */ /* be tidy */
pfree(tab); pfree(tab);