diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index efa25a1ad91b2d786808138e421ce0965331bfe7..952109f7845483f0c19e9de9940fbe90e60ee05d 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.169 2008/01/01 19:45:49 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.170 2008/01/09 21:52:36 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -38,6 +38,7 @@ #include "parser/parse_expr.h" #include "parser/parse_func.h" #include "parser/parsetree.h" +#include "storage/proc.h" #include "storage/procarray.h" #include "utils/acl.h" #include "utils/builtins.h" @@ -630,11 +631,19 @@ DefineIndex(RangeVar *heapRelation, * We can exclude any running transactions that have xmin >= the xmax of * our reference snapshot, since they are clearly not interested in any * missing older tuples. Transactions in other DBs aren't a problem - * either, since they'll never even be able to see this index. Also, - * GetCurrentVirtualXIDs never reports our own vxid, so we need not check - * for that. + * either, since they'll never even be able to see this index. + * + * We can also exclude autovacuum processes and processes running manual + * lazy VACUUMs, because they won't be fazed by missing index entries + * either. (Manual ANALYZEs, however, can't be excluded because they + * might be within transactions that are going to do arbitrary operations + * later.) + * + * Also, GetCurrentVirtualXIDs never reports our own vxid, so we need not + * check for that. */ - old_snapshots = GetCurrentVirtualXIDs(ActiveSnapshot->xmax, false); + old_snapshots = GetCurrentVirtualXIDs(ActiveSnapshot->xmax, false, + PROC_IS_AUTOVACUUM | PROC_IN_VACUUM); while (VirtualTransactionIdIsValid(*old_snapshots)) { diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index 89441f64f1e2adc63fe5d801da85de4985b8b3ce..575b138c435b3ddf49e53b0bef8fc207cb4e0cb8 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -23,7 +23,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.39 2008/01/01 19:45:51 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.40 2008/01/09 21:52:36 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1006,10 +1006,12 @@ IsBackendPid(int pid) * * If limitXmin is not InvalidTransactionId, we skip any backends * with xmin >= limitXmin. If allDbs is false, we skip backends attached - * to other databases. Also, our own process is always skipped. + * to other databases. If excludeVacuum isn't zero, we skip processes for + * which (excludeVacuum & vacuumFlags) is not zero. Also, our own process + * is always skipped. */ VirtualTransactionId * -GetCurrentVirtualXIDs(TransactionId limitXmin, bool allDbs) +GetCurrentVirtualXIDs(TransactionId limitXmin, bool allDbs, int excludeVacuum) { VirtualTransactionId *vxids; ProcArrayStruct *arrayP = procArray; @@ -1029,6 +1031,9 @@ GetCurrentVirtualXIDs(TransactionId limitXmin, bool allDbs) if (proc == MyProc) continue; + if (excludeVacuum & proc->vacuumFlags) + continue; + if (allDbs || proc->databaseId == MyDatabaseId) { /* Fetch xmin just once - might change on us? */ diff --git a/src/include/storage/procarray.h b/src/include/storage/procarray.h index 5e0b1fd6ba57198a3ca4942f033191c0ac3aa5cc..26b27fa941806568c35e06ed5831047e8fd9df71 100644 --- a/src/include/storage/procarray.h +++ b/src/include/storage/procarray.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/storage/procarray.h,v 1.19 2008/01/01 19:45:59 momjian Exp $ + * $PostgreSQL: pgsql/src/include/storage/procarray.h,v 1.20 2008/01/09 21:52:36 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -37,7 +37,7 @@ extern int BackendXidGetPid(TransactionId xid); extern bool IsBackendPid(int pid); extern VirtualTransactionId *GetCurrentVirtualXIDs(TransactionId limitXmin, - bool allDbs); + bool allDbs, int excludeVacuum); extern int CountActiveBackends(void); extern int CountDBBackends(Oid databaseid); extern int CountUserBackends(Oid roleid);