Avoid having autovacuum run multiple ANALYZE commands in a single transaction,
authorAlvaro Herrera <[email protected]>
Thu, 14 Jun 2007 13:54:28 +0000 (13:54 +0000)
committerAlvaro Herrera <[email protected]>
Thu, 14 Jun 2007 13:54:28 +0000 (13:54 +0000)
to prevent possible deadlock problems.  Per request from Tom Lane.

src/backend/commands/vacuum.c

index 32df54f27ff58903026ded0b3409dbec5a4b4f6d..57dcc2249b1eb3fdfcf5be62a545b257b92fd062 100644 (file)
@@ -338,14 +338,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;