From: Alvaro Herrera Date: Thu, 14 Jun 2007 13:54:40 +0000 (+0000) Subject: Avoid having autovacuum run multiple ANALYZE commands in a single transaction, X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=4440954f869d483bddd0a57f904b33c6be870d3e;p=users%2Fbernd%2Fpostgres.git Avoid having autovacuum run multiple ANALYZE commands in a single transaction, to prevent possible deadlock problems. Per request from Tom Lane. --- diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index b38850a65b..653dbb36f6 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -389,14 +389,17 @@ vacuum(VacuumStmt *vacstmt, List *relids) * For ANALYZE (no VACUUM): if inside a transaction block, we cannot * start/commit our own transactions. Also, there's no need to do so if * only processing one relation. For multiple relations when not within a - * transaction block, use own transactions so we can release locks sooner. + * transaction block, and also in an autovacuum worker, use own + * transactions so we can release locks sooner. */ if (vacstmt->vacuum) use_own_xacts = true; else { Assert(vacstmt->analyze); - if (in_outer_xact) + if (IsAutoVacuumProcess()) + use_own_xacts = true; + else if (in_outer_xact) use_own_xacts = false; else if (list_length(relations) > 1) use_own_xacts = true;