Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteb63cc3

Browse files
committed
Arrange for autovacuum to be killed when another operation wants to be alone
accessing it, like DROP DATABASE. This allows the regression tests to passwith autovacuum enabled, which open the gates for finally enabling autovacuumby default.
1 parent0260989 commiteb63cc3

File tree

9 files changed

+59
-23
lines changed

9 files changed

+59
-23
lines changed

‎src/backend/access/transam/twophase.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
*$PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.26 2007/01/05 22:19:23 momjian Exp $
10+
*$PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.27 2007/01/16 13:28:56 alvherre Exp $
1111
*
1212
* NOTES
1313
*Each global transaction is associated with a global transaction
@@ -280,6 +280,7 @@ MarkAsPreparing(TransactionId xid, const char *gid,
280280
gxact->proc.databaseId=databaseid;
281281
gxact->proc.roleId=owner;
282282
gxact->proc.inVacuum= false;
283+
gxact->proc.isAutovacuum= false;
283284
gxact->proc.lwWaiting= false;
284285
gxact->proc.lwExclusive= false;
285286
gxact->proc.lwWaitLink=NULL;

‎src/backend/commands/dbcommands.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.188 2007/01/05 22:19:25 momjian Exp $
16+
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.189 2007/01/16 13:28:56 alvherre Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -250,11 +250,11 @@ createdb(const CreatedbStmt *stmt)
250250
* (exception is to allow CREATE DB while connected to template1).
251251
* Otherwise we might copy inconsistent data.
252252
*/
253-
if (DatabaseHasActiveBackends(src_dboid, true))
253+
if (DatabaseCancelAutovacuumActivity(src_dboid, true))
254254
ereport(ERROR,
255255
(errcode(ERRCODE_OBJECT_IN_USE),
256-
errmsg("source database \"%s\" is being accessed by other users",
257-
dbtemplate)));
256+
errmsg("source database \"%s\" is being accessed by other users",
257+
dbtemplate)));
258258

259259
/* If encoding is defaulted, use source's encoding */
260260
if (encoding<0)
@@ -602,7 +602,7 @@ dropdb(const char *dbname, bool missing_ok)
602602
* Check for active backends in the target database. (Because we hold the
603603
* database lock, no new ones can start after this.)
604604
*/
605-
if (DatabaseHasActiveBackends(db_id, false))
605+
if (DatabaseCancelAutovacuumActivity(db_id, false))
606606
ereport(ERROR,
607607
(errcode(ERRCODE_OBJECT_IN_USE),
608608
errmsg("database \"%s\" is being accessed by other users",
@@ -706,7 +706,7 @@ RenameDatabase(const char *oldname, const char *newname)
706706
* Make sure the database does not have active sessions. This is the same
707707
* concern as above, but applied to other sessions.
708708
*/
709-
if (DatabaseHasActiveBackends(db_id, false))
709+
if (DatabaseCancelAutovacuumActivity(db_id, false))
710710
ereport(ERROR,
711711
(errcode(ERRCODE_OBJECT_IN_USE),
712712
errmsg("database \"%s\" is being accessed by other users",

‎src/backend/postmaster/autovacuum.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.30 2007/01/05 22:19:36 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.31 2007/01/16 13:28:56 alvherre Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -216,6 +216,15 @@ autovac_forkexec(void)
216216

217217
returnpostmaster_forkexec(ac,av);
218218
}
219+
220+
/*
221+
* We need this set from the outside, before InitProcess is called
222+
*/
223+
void
224+
AutovacuumIAm(void)
225+
{
226+
am_autovacuum= true;
227+
}
219228
#endif/* EXEC_BACKEND */
220229

221230
/*
@@ -307,8 +316,8 @@ AutoVacMain(int argc, char *argv[])
307316
EmitErrorReport();
308317

309318
/*
310-
* We can now go away.Note that because we'll call InitProcess, a
311-
* callbackwill be registered to do ProcKill, which will clean up
319+
* We can now go away.Note that because we called InitProcess, a
320+
* callbackwas registered to do ProcKill, which will clean up
312321
* necessary state.
313322
*/
314323
proc_exit(0);

‎src/backend/postmaster/postmaster.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.507 2007/01/05 22:19:36 momjian Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.508 2007/01/16 13:28:56 alvherre Exp $
4141
*
4242
* NOTES
4343
*
@@ -3298,6 +3298,10 @@ SubPostmasterMain(int argc, char *argv[])
32983298
strcmp(argv[1],"--forkboot")==0)
32993299
PGSharedMemoryReAttach();
33003300

3301+
/* autovacuum needs this set before calling InitProcess */
3302+
if (strcmp(argv[1],"--forkautovac")==0)
3303+
AutovacuumIAm();
3304+
33013305
/*
33023306
* Start our win32 signal implementation. This has to be done after we
33033307
* read the backend variables, because we need to pick up the signal pipe

‎src/backend/storage/ipc/procarray.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@
2323
*
2424
*
2525
* IDENTIFICATION
26-
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.20 2007/01/05 22:19:38 momjian Exp $
26+
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.21 2007/01/16 13:28:56 alvherre Exp $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
3030
#include"postgres.h"
3131

32+
#include<signal.h>
33+
3234
#include"access/subtrans.h"
3335
#include"access/transam.h"
3436
#include"access/xact.h"
@@ -678,7 +680,9 @@ GetSnapshotData(Snapshot snapshot, bool serializable)
678680
}
679681

680682
/*
681-
* DatabaseHasActiveBackends -- are there any backends running in the given DB
683+
* DatabaseCancelAutovacuumActivity -- are there any backends running in the
684+
* given DB, apart from autovacuum? If an autovacuum process is running on the
685+
* database, kill it and restart the counting.
682686
*
683687
* If 'ignoreMyself' is TRUE, ignore this particular backend while checking
684688
* for backends in the target database.
@@ -691,11 +695,16 @@ GetSnapshotData(Snapshot snapshot, bool serializable)
691695
* backend startup.
692696
*/
693697
bool
694-
DatabaseHasActiveBackends(OiddatabaseId,boolignoreMyself)
698+
DatabaseCancelAutovacuumActivity(OiddatabaseId,boolignoreMyself)
695699
{
696-
boolresult= false;
697700
ProcArrayStruct*arrayP=procArray;
698701
intindex;
702+
intnum;
703+
704+
restart:
705+
num=0;
706+
707+
CHECK_FOR_INTERRUPTS();
699708

700709
LWLockAcquire(ProcArrayLock,LW_SHARED);
701710

@@ -708,14 +717,22 @@ DatabaseHasActiveBackends(Oid databaseId, bool ignoreMyself)
708717
if (ignoreMyself&&proc==MyProc)
709718
continue;
710719

711-
result= true;
712-
break;
720+
num++;
721+
722+
if (proc->isAutovacuum)
723+
{
724+
/* an autovacuum -- kill it and restart */
725+
LWLockRelease(ProcArrayLock);
726+
kill(proc->pid,SIGINT);
727+
pg_usleep(100*1000);/* 100ms */
728+
gotorestart;
729+
}
713730
}
714731
}
715732

716733
LWLockRelease(ProcArrayLock);
717734

718-
returnresult;
735+
return(num!=0);
719736
}
720737

721738
/*

‎src/backend/storage/lmgr/proc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.182 2007/01/05 22:19:38 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.183 2007/01/16 13:28:56 alvherre Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -38,6 +38,7 @@
3838
#include"access/transam.h"
3939
#include"access/xact.h"
4040
#include"miscadmin.h"
41+
#include"postmaster/autovacuum.h"
4142
#include"storage/ipc.h"
4243
#include"storage/proc.h"
4344
#include"storage/procarray.h"
@@ -258,6 +259,7 @@ InitProcess(void)
258259
MyProc->databaseId=InvalidOid;
259260
MyProc->roleId=InvalidOid;
260261
MyProc->inVacuum= false;
262+
MyProc->isAutovacuum=IsAutoVacuumProcess();
261263
MyProc->lwWaiting= false;
262264
MyProc->lwExclusive= false;
263265
MyProc->lwWaitLink=NULL;
@@ -390,6 +392,7 @@ InitDummyProcess(void)
390392
MyProc->databaseId=InvalidOid;
391393
MyProc->roleId=InvalidOid;
392394
MyProc->inVacuum= false;
395+
MyProc->isAutovacuum= false;
393396
MyProc->lwWaiting= false;
394397
MyProc->lwExclusive= false;
395398
MyProc->lwWaitLink=NULL;

‎src/include/postmaster/autovacuum.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/postmaster/autovacuum.h,v 1.6 2007/01/05 22:19:57momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/postmaster/autovacuum.h,v 1.7 2007/01/16 13:28:57alvherre Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -36,6 +36,7 @@ extern void autovac_stopped(void);
3636

3737
#ifdefEXEC_BACKEND
3838
externvoidAutoVacMain(intargc,char*argv[]);
39+
externvoidAutovacuumIAm(void);
3940
#endif
4041

4142
#endif/* AUTOVACUUM_H */

‎src/include/storage/proc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.92 2007/01/05 22:19:58 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.93 2007/01/16 13:28:57 alvherre Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -75,6 +75,7 @@ struct PGPROC
7575
OidroleId;/* OID of role using this backend */
7676

7777
boolinVacuum;/* true if current xact is a LAZY VACUUM */
78+
boolisAutovacuum;/* true if it's autovacuum */
7879

7980
/* Info about LWLock the process is currently waiting for, if any. */
8081
boollwWaiting;/* true if waiting for an LW lock */

‎src/include/storage/procarray.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/storage/procarray.h,v 1.11 2007/01/05 22:19:58 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/storage/procarray.h,v 1.12 2007/01/16 13:28:57 alvherre Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -29,7 +29,7 @@ extern TransactionId GetOldestXmin(bool allDbs, bool ignoreVacuum);
2929
externPGPROC*BackendPidGetProc(intpid);
3030
externintBackendXidGetPid(TransactionIdxid);
3131
externboolIsBackendPid(intpid);
32-
externboolDatabaseHasActiveBackends(OiddatabaseId,boolignoreMyself);
32+
externboolDatabaseCancelAutovacuumActivity(OiddatabaseId,boolignoreMyself);
3333

3434
externintCountActiveBackends(void);
3535
externintCountDBBackends(Oiddatabaseid);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp