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

Commit10af02b

Browse files
committed
Arrange for SIGINT in autovacuum workers to cancel the current table and
continue with the schedule. Change current uses of SIGINT to abort a workerinto SIGTERM, which keeps the old behaviour of terminating the process.Patch from ITAGAKI Takahiro, with some editorializing of my own.
1 parentc786796 commit10af02b

File tree

4 files changed

+63
-15
lines changed

4 files changed

+63
-15
lines changed

‎src/backend/postmaster/autovacuum.c

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
*
5656
*
5757
* IDENTIFICATION
58-
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.51 2007/06/25 16:09:03 alvherre Exp $
58+
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.52 2007/06/29 17:07:39 alvherre Exp $
5959
*
6060
*-------------------------------------------------------------------------
6161
*/
@@ -75,6 +75,7 @@
7575
#include"catalog/namespace.h"
7676
#include"catalog/pg_autovacuum.h"
7777
#include"catalog/pg_database.h"
78+
#include"commands/dbcommands.h"
7879
#include"commands/vacuum.h"
7980
#include"libpq/hba.h"
8081
#include"libpq/pqsignal.h"
@@ -2025,12 +2026,53 @@ do_autovacuum(void)
20252026
autovac_balance_cost();
20262027
LWLockRelease(AutovacuumLock);
20272028

2028-
/* have at it */
2029-
autovacuum_do_vac_analyze(tab->at_relid,
2030-
tab->at_dovacuum,
2031-
tab->at_doanalyze,
2032-
tab->at_freeze_min_age,
2033-
bstrategy);
2029+
/*
2030+
* We will abort vacuuming the current table if we are interrupted, and
2031+
* continue with the next one in schedule; but if anything else
2032+
* happens, we will do our usual error handling which is to cause the
2033+
* worker process to exit.
2034+
*/
2035+
PG_TRY();
2036+
{
2037+
/* have at it */
2038+
autovacuum_do_vac_analyze(tab->at_relid,
2039+
tab->at_dovacuum,
2040+
tab->at_doanalyze,
2041+
tab->at_freeze_min_age,
2042+
bstrategy);
2043+
}
2044+
PG_CATCH();
2045+
{
2046+
ErrorData*errdata;
2047+
2048+
MemoryContextSwitchTo(TopTransactionContext);
2049+
errdata=CopyErrorData();
2050+
2051+
/*
2052+
* If we errored out due to a cancel request, abort and restart the
2053+
* transaction and go to the next table. Otherwise rethrow the
2054+
* error so that the outermost handler deals with it.
2055+
*/
2056+
if (errdata->sqlerrcode==ERRCODE_QUERY_CANCELED)
2057+
{
2058+
HOLD_INTERRUPTS();
2059+
elog(LOG,"cancelling autovacuum of table \"%s.%s.%s\"",
2060+
get_database_name(MyDatabaseId),
2061+
get_namespace_name(get_rel_namespace(tab->at_relid)),
2062+
get_rel_name(tab->at_relid));
2063+
2064+
AbortOutOfAnyTransaction();
2065+
FlushErrorState();
2066+
2067+
/* restart our transaction for the following operations */
2068+
StartTransactionCommand();
2069+
RESUME_INTERRUPTS();
2070+
}
2071+
else
2072+
PG_RE_THROW();
2073+
}
2074+
PG_END_TRY();
2075+
20342076
/* be tidy */
20352077
pfree(tab);
20362078
}

‎src/backend/postmaster/postmaster.c

Lines changed: 2 additions & 2 deletions
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.528 2007/06/25 16:09:03 alvherre Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.529 2007/06/29 17:07:39 alvherre Exp $
4141
*
4242
* NOTES
4343
*
@@ -1875,7 +1875,7 @@ pmdie(SIGNAL_ARGS)
18751875

18761876
/* autovacuum workers are shut down immediately */
18771877
if (DLGetHead(BackendList))
1878-
SignalSomeChildren(SIGINT, true);
1878+
SignalSomeChildren(SIGTERM, true);
18791879

18801880
if (DLGetHead(BackendList))
18811881
break;/* let reaper() handle this */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
*
2525
* IDENTIFICATION
26-
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.26 2007/06/07 21:45:59 tgl Exp $
26+
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.27 2007/06/29 17:07:39 alvherre Exp $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
@@ -1008,7 +1008,7 @@ CheckOtherDBBackends(Oid databaseId)
10081008
*/
10091009
LWLockRelease(ProcArrayLock);
10101010

1011-
(void)kill(autopid,SIGINT);/* ignore any error */
1011+
(void)kill(autopid,SIGTERM);/* ignore any error */
10121012

10131013
break;
10141014
}

‎src/backend/tcop/postgres.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.534 2007/06/23 22:12:52 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.535 2007/06/29 17:07:39 alvherre Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -51,6 +51,7 @@
5151
#include"optimizer/planner.h"
5252
#include"parser/analyze.h"
5353
#include"parser/parser.h"
54+
#include"postmaster/autovacuum.h"
5455
#include"rewrite/rewriteHandler.h"
5556
#include"storage/freespace.h"
5657
#include"storage/ipc.h"
@@ -2540,9 +2541,14 @@ ProcessInterrupts(void)
25402541
ImmediateInterruptOK= false;/* not idle anymore */
25412542
DisableNotifyInterrupt();
25422543
DisableCatchupInterrupt();
2543-
ereport(FATAL,
2544-
(errcode(ERRCODE_ADMIN_SHUTDOWN),
2545-
errmsg("terminating connection due to administrator command")));
2544+
if (IsAutoVacuumWorkerProcess())
2545+
ereport(FATAL,
2546+
(errcode(ERRCODE_ADMIN_SHUTDOWN),
2547+
errmsg("terminating autovacuum process due to administrator command")));
2548+
else
2549+
ereport(FATAL,
2550+
(errcode(ERRCODE_ADMIN_SHUTDOWN),
2551+
errmsg("terminating connection due to administrator command")));
25462552
}
25472553
if (QueryCancelPending)
25482554
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp