diff options
| author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2007-01-16 13:28:57 +0000 |
|---|---|---|
| committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2007-01-16 13:28:57 +0000 |
| commit | eb63cc3da82cec03c54a9534a6c91d287078abd1 (patch) | |
| tree | a8181fbd037cc02c1eeb68202b8632b20f536665 /src/backend/storage | |
| parent | 02609893da8cac7689ec5173bc7d815e6f27ad2e (diff) | |
| download | postgresql-eb63cc3da82cec03c54a9534a6c91d287078abd1.tar.gz | |
Arrange for autovacuum to be killed when another operation wants to be alone
accessing it, like DROP DATABASE. This allows the regression tests to pass
with autovacuum enabled, which open the gates for finally enabling autovacuum
by default.
Diffstat (limited to 'src/backend/storage')
| -rw-r--r-- | src/backend/storage/ipc/procarray.c | 31 | ||||
| -rw-r--r-- | src/backend/storage/lmgr/proc.c | 5 |
2 files changed, 28 insertions, 8 deletions
diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index b31bdf9b7d..19e5efa683 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -23,12 +23,14 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.20 2007/01/05 22:19:38 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.21 2007/01/16 13:28:56 alvherre Exp $ * *------------------------------------------------------------------------- */ #include "postgres.h" +#include <signal.h> + #include "access/subtrans.h" #include "access/transam.h" #include "access/xact.h" @@ -678,7 +680,9 @@ GetSnapshotData(Snapshot snapshot, bool serializable) } /* - * DatabaseHasActiveBackends -- are there any backends running in the given DB + * DatabaseCancelAutovacuumActivity -- are there any backends running in the + * given DB, apart from autovacuum? If an autovacuum process is running on the + * database, kill it and restart the counting. * * If 'ignoreMyself' is TRUE, ignore this particular backend while checking * for backends in the target database. @@ -691,11 +695,16 @@ GetSnapshotData(Snapshot snapshot, bool serializable) * backend startup. */ bool -DatabaseHasActiveBackends(Oid databaseId, bool ignoreMyself) +DatabaseCancelAutovacuumActivity(Oid databaseId, bool ignoreMyself) { - bool result = false; ProcArrayStruct *arrayP = procArray; int index; + int num; + +restart: + num = 0; + + CHECK_FOR_INTERRUPTS(); LWLockAcquire(ProcArrayLock, LW_SHARED); @@ -708,14 +717,22 @@ DatabaseHasActiveBackends(Oid databaseId, bool ignoreMyself) if (ignoreMyself && proc == MyProc) continue; - result = true; - break; + num++; + + if (proc->isAutovacuum) + { + /* an autovacuum -- kill it and restart */ + LWLockRelease(ProcArrayLock); + kill(proc->pid, SIGINT); + pg_usleep(100 * 1000); /* 100ms */ + goto restart; + } } } LWLockRelease(ProcArrayLock); - return result; + return (num != 0); } /* diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index d4500b5c35..6e2a0ce81c 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.182 2007/01/05 22:19:38 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.183 2007/01/16 13:28:56 alvherre Exp $ * *------------------------------------------------------------------------- */ @@ -38,6 +38,7 @@ #include "access/transam.h" #include "access/xact.h" #include "miscadmin.h" +#include "postmaster/autovacuum.h" #include "storage/ipc.h" #include "storage/proc.h" #include "storage/procarray.h" @@ -258,6 +259,7 @@ InitProcess(void) MyProc->databaseId = InvalidOid; MyProc->roleId = InvalidOid; MyProc->inVacuum = false; + MyProc->isAutovacuum = IsAutoVacuumProcess(); MyProc->lwWaiting = false; MyProc->lwExclusive = false; MyProc->lwWaitLink = NULL; @@ -390,6 +392,7 @@ InitDummyProcess(void) MyProc->databaseId = InvalidOid; MyProc->roleId = InvalidOid; MyProc->inVacuum = false; + MyProc->isAutovacuum = false; MyProc->lwWaiting = false; MyProc->lwExclusive = false; MyProc->lwWaitLink = NULL; |
