#include "catalog/namespace.h"
#include "catalog/pg_autovacuum.h"
#include "catalog/pg_database.h"
+#include "commands/dbcommands.h"
#include "commands/vacuum.h"
#include "libpq/hba.h"
#include "libpq/pqsignal.h"
autovac_balance_cost();
LWLockRelease(AutovacuumLock);
- /* have at it */
- autovacuum_do_vac_analyze(tab->at_relid,
- tab->at_dovacuum,
- tab->at_doanalyze,
- tab->at_freeze_min_age,
- bstrategy);
+ /*
+ * We will abort vacuuming the current table if we are interrupted, and
+ * continue with the next one in schedule; but if anything else
+ * happens, we will do our usual error handling which is to cause the
+ * worker process to exit.
+ */
+ PG_TRY();
+ {
+ /* have at it */
+ autovacuum_do_vac_analyze(tab->at_relid,
+ tab->at_dovacuum,
+ tab->at_doanalyze,
+ tab->at_freeze_min_age,
+ bstrategy);
+ }
+ PG_CATCH();
+ {
+ ErrorData *errdata;
+
+ MemoryContextSwitchTo(TopTransactionContext);
+ errdata = CopyErrorData();
+
+ /*
+ * If we errored out due to a cancel request, abort and restart the
+ * transaction and go to the next table. Otherwise rethrow the
+ * error so that the outermost handler deals with it.
+ */
+ if (errdata->sqlerrcode == ERRCODE_QUERY_CANCELED)
+ {
+ HOLD_INTERRUPTS();
+ elog(LOG, "cancelling autovacuum of table \"%s.%s.%s\"",
+ get_database_name(MyDatabaseId),
+ get_namespace_name(get_rel_namespace(tab->at_relid)),
+ get_rel_name(tab->at_relid));
+
+ AbortOutOfAnyTransaction();
+ FlushErrorState();
+
+ /* restart our transaction for the following operations */
+ StartTransactionCommand();
+ RESUME_INTERRUPTS();
+ }
+ else
+ PG_RE_THROW();
+ }
+ PG_END_TRY();
+
/* be tidy */
pfree(tab);
}
/* autovacuum workers are shut down immediately */
if (DLGetHead(BackendList))
- SignalSomeChildren(SIGINT, true);
+ SignalSomeChildren(SIGTERM, true);
if (DLGetHead(BackendList))
break; /* let reaper() handle this */
#include "optimizer/planner.h"
#include "parser/analyze.h"
#include "parser/parser.h"
+#include "postmaster/autovacuum.h"
#include "rewrite/rewriteHandler.h"
#include "storage/freespace.h"
#include "storage/ipc.h"
ImmediateInterruptOK = false; /* not idle anymore */
DisableNotifyInterrupt();
DisableCatchupInterrupt();
- ereport(FATAL,
- (errcode(ERRCODE_ADMIN_SHUTDOWN),
- errmsg("terminating connection due to administrator command")));
+ if (IsAutoVacuumWorkerProcess())
+ ereport(FATAL,
+ (errcode(ERRCODE_ADMIN_SHUTDOWN),
+ errmsg("terminating autovacuum process due to administrator command")));
+ else
+ ereport(FATAL,
+ (errcode(ERRCODE_ADMIN_SHUTDOWN),
+ errmsg("terminating connection due to administrator command")));
}
if (QueryCancelPending)
{