* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.26 2007/01/05 22:19:23 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.27 2007/01/16 13:28:56 alvherre Exp $
*
* NOTES
* Each global transaction is associated with a global transaction
gxact->proc.databaseId = databaseid;
gxact->proc.roleId = owner;
gxact->proc.inVacuum = false;
+ gxact->proc.isAutovacuum = false;
gxact->proc.lwWaiting = false;
gxact->proc.lwExclusive = false;
gxact->proc.lwWaitLink = NULL;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.188 2007/01/05 22:19:25 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.189 2007/01/16 13:28:56 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
* (exception is to allow CREATE DB while connected to template1).
* Otherwise we might copy inconsistent data.
*/
- if (DatabaseHasActiveBackends(src_dboid, true))
+ if (DatabaseCancelAutovacuumActivity(src_dboid, true))
ereport(ERROR,
(errcode(ERRCODE_OBJECT_IN_USE),
- errmsg("source database \"%s\" is being accessed by other users",
- dbtemplate)));
+ errmsg("source database \"%s\" is being accessed by other users",
+ dbtemplate)));
/* If encoding is defaulted, use source's encoding */
if (encoding < 0)
* Check for active backends in the target database. (Because we hold the
* database lock, no new ones can start after this.)
*/
- if (DatabaseHasActiveBackends(db_id, false))
+ if (DatabaseCancelAutovacuumActivity(db_id, false))
ereport(ERROR,
(errcode(ERRCODE_OBJECT_IN_USE),
errmsg("database \"%s\" is being accessed by other users",
* Make sure the database does not have active sessions. This is the same
* concern as above, but applied to other sessions.
*/
- if (DatabaseHasActiveBackends(db_id, false))
+ if (DatabaseCancelAutovacuumActivity(db_id, false))
ereport(ERROR,
(errcode(ERRCODE_OBJECT_IN_USE),
errmsg("database \"%s\" is being accessed by other users",
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.30 2007/01/05 22:19:36 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.31 2007/01/16 13:28:56 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
return postmaster_forkexec(ac, av);
}
+
+/*
+ * We need this set from the outside, before InitProcess is called
+ */
+void
+AutovacuumIAm(void)
+{
+ am_autovacuum = true;
+}
#endif /* EXEC_BACKEND */
/*
EmitErrorReport();
/*
- * We can now go away. Note that because we'll call InitProcess, a
- * callback will be registered to do ProcKill, which will clean up
+ * We can now go away. Note that because we called InitProcess, a
+ * callback was registered to do ProcKill, which will clean up
* necessary state.
*/
proc_exit(0);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.507 2007/01/05 22:19:36 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.508 2007/01/16 13:28:56 alvherre Exp $
*
* NOTES
*
strcmp(argv[1], "--forkboot") == 0)
PGSharedMemoryReAttach();
+ /* autovacuum needs this set before calling InitProcess */
+ if (strcmp(argv[1], "--forkautovac") == 0)
+ AutovacuumIAm();
+
/*
* Start our win32 signal implementation. This has to be done after we
* read the backend variables, because we need to pick up the signal pipe
*
*
* 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"
}
/*
- * 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.
* 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);
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);
}
/*
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
#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"
MyProc->databaseId = InvalidOid;
MyProc->roleId = InvalidOid;
MyProc->inVacuum = false;
+ MyProc->isAutovacuum = IsAutoVacuumProcess();
MyProc->lwWaiting = false;
MyProc->lwExclusive = false;
MyProc->lwWaitLink = NULL;
MyProc->databaseId = InvalidOid;
MyProc->roleId = InvalidOid;
MyProc->inVacuum = false;
+ MyProc->isAutovacuum = false;
MyProc->lwWaiting = false;
MyProc->lwExclusive = false;
MyProc->lwWaitLink = NULL;
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/postmaster/autovacuum.h,v 1.6 2007/01/05 22:19:57 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/postmaster/autovacuum.h,v 1.7 2007/01/16 13:28:57 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
#ifdef EXEC_BACKEND
extern void AutoVacMain(int argc, char *argv[]);
+extern void AutovacuumIAm(void);
#endif
#endif /* AUTOVACUUM_H */
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.92 2007/01/05 22:19:58 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.93 2007/01/16 13:28:57 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
Oid roleId; /* OID of role using this backend */
bool inVacuum; /* true if current xact is a LAZY VACUUM */
+ bool isAutovacuum; /* true if it's autovacuum */
/* Info about LWLock the process is currently waiting for, if any. */
bool lwWaiting; /* true if waiting for an LW lock */
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/storage/procarray.h,v 1.11 2007/01/05 22:19:58 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/storage/procarray.h,v 1.12 2007/01/16 13:28:57 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
extern PGPROC *BackendPidGetProc(int pid);
extern int BackendXidGetPid(TransactionId xid);
extern bool IsBackendPid(int pid);
-extern bool DatabaseHasActiveBackends(Oid databaseId, bool ignoreMyself);
+extern bool DatabaseCancelAutovacuumActivity(Oid databaseId, bool ignoreMyself);
extern int CountActiveBackends(void);
extern int CountDBBackends(Oid databaseid);