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

Commit2627c83

Browse files
committed
Minor changes to autovacuum worker: change error handling so that it continues
with the next table on schedule instead of exiting, in all cases instead ofjust on query cancel.Add a errcontext() line indicating the activity of the worker to the errormessage when it is cancelled.Change the WorkerInfo struct to contain a pointer to the worker's PGPROCinstead of just the PID.Add forgotten post-auth delays, per Simon Riggs. Also to autovac launcher.
1 parentc29a9c3 commit2627c83

File tree

1 file changed

+52
-43
lines changed

1 file changed

+52
-43
lines changed

‎src/backend/postmaster/autovacuum.c

Lines changed: 52 additions & 43 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.61 2007/09/2404:12:01 alvherre Exp $
58+
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.62 2007/10/2419:08:25 alvherre Exp $
5959
*
6060
*-------------------------------------------------------------------------
6161
*/
@@ -182,7 +182,7 @@ typedef struct autovac_table
182182
* wi_linksentry into free list or running list
183183
* wi_dboidOID of the database this worker is supposed to work on
184184
* wi_tableoidOID of the table currently being vacuumed
185-
*wi_workerpidPIDof the running worker,0 if not yet started
185+
*wi_procpointer to PGPROCof the running worker,NULL if not started
186186
* wi_launchtime Time at which this worker was launched
187187
* wi_cost_*Vacuum cost-based delay parameters current in this worker
188188
*
@@ -196,7 +196,7 @@ typedef struct WorkerInfoData
196196
SHM_QUEUEwi_links;
197197
Oidwi_dboid;
198198
Oidwi_tableoid;
199-
intwi_workerpid;
199+
PGPROC*wi_proc;
200200
TimestampTzwi_launchtime;
201201
intwi_cost_delay;
202202
intwi_cost_limit;
@@ -395,6 +395,9 @@ AutoVacLauncherMain(int argc, char *argv[])
395395
/* Identify myself via ps */
396396
init_ps_display("autovacuum launcher process","","","");
397397

398+
if (PostAuthDelay)
399+
pg_usleep(PostAuthDelay*1000000L);
400+
398401
SetProcessingMode(InitProcessing);
399402

400403
/*
@@ -694,7 +697,7 @@ AutoVacLauncherMain(int argc, char *argv[])
694697
worker= (WorkerInfo)MAKE_PTR(AutoVacuumShmem->av_startingWorker);
695698
worker->wi_dboid=InvalidOid;
696699
worker->wi_tableoid=InvalidOid;
697-
worker->wi_workerpid=0;
700+
worker->wi_proc=NULL;
698701
worker->wi_launchtime=0;
699702
worker->wi_links.next=AutoVacuumShmem->av_freeWorkers;
700703
AutoVacuumShmem->av_freeWorkers=MAKE_OFFSET(worker);
@@ -1198,7 +1201,7 @@ do_start_worker(void)
11981201
AutoVacuumShmem->av_freeWorkers=worker->wi_links.next;
11991202

12001203
worker->wi_dboid=avdb->adw_datid;
1201-
worker->wi_workerpid=0;
1204+
worker->wi_proc=NULL;
12021205
worker->wi_launchtime=GetCurrentTimestamp();
12031206

12041207
AutoVacuumShmem->av_startingWorker=sworker;
@@ -1437,6 +1440,9 @@ AutoVacWorkerMain(int argc, char *argv[])
14371440
/* Identify myself via ps */
14381441
init_ps_display("autovacuum worker process","","","");
14391442

1443+
if (PostAuthDelay)
1444+
pg_usleep(PostAuthDelay*1000000L);
1445+
14401446
SetProcessingMode(InitProcessing);
14411447

14421448
/*
@@ -1542,7 +1548,7 @@ AutoVacWorkerMain(int argc, char *argv[])
15421548
{
15431549
MyWorkerInfo= (WorkerInfo)MAKE_PTR(AutoVacuumShmem->av_startingWorker);
15441550
dbid=MyWorkerInfo->wi_dboid;
1545-
MyWorkerInfo->wi_workerpid=MyProcPid;
1551+
MyWorkerInfo->wi_proc=MyProc;
15461552

15471553
/* insert into the running list */
15481554
SHMQueueInsertBefore(&AutoVacuumShmem->av_runningWorkers,
@@ -1637,7 +1643,7 @@ FreeWorkerInfo(int code, Datum arg)
16371643
MyWorkerInfo->wi_links.next=AutoVacuumShmem->av_freeWorkers;
16381644
MyWorkerInfo->wi_dboid=InvalidOid;
16391645
MyWorkerInfo->wi_tableoid=InvalidOid;
1640-
MyWorkerInfo->wi_workerpid=0;
1646+
MyWorkerInfo->wi_proc=NULL;
16411647
MyWorkerInfo->wi_launchtime=0;
16421648
MyWorkerInfo->wi_cost_delay=0;
16431649
MyWorkerInfo->wi_cost_limit=0;
@@ -1701,7 +1707,7 @@ autovac_balance_cost(void)
17011707
offsetof(WorkerInfoData,wi_links));
17021708
while (worker)
17031709
{
1704-
if (worker->wi_workerpid!=0&&
1710+
if (worker->wi_proc!=NULL&&
17051711
worker->wi_cost_limit_base>0&&worker->wi_cost_delay>0)
17061712
cost_total+=
17071713
(double)worker->wi_cost_limit_base /worker->wi_cost_delay;
@@ -1724,7 +1730,7 @@ autovac_balance_cost(void)
17241730
offsetof(WorkerInfoData,wi_links));
17251731
while (worker)
17261732
{
1727-
if (worker->wi_workerpid!=0&&
1733+
if (worker->wi_proc!=NULL&&
17281734
worker->wi_cost_limit_base>0&&worker->wi_cost_delay>0)
17291735
{
17301736
intlimit= (int)
@@ -1737,7 +1743,7 @@ autovac_balance_cost(void)
17371743
worker->wi_cost_limit=Max(Min(limit,worker->wi_cost_limit_base),1);
17381744

17391745
elog(DEBUG2,"autovac_balance_cost(pid=%u db=%u, rel=%u, cost_limit=%d, cost_delay=%d)",
1740-
worker->wi_workerpid,worker->wi_dboid,
1746+
worker->wi_proc->pid,worker->wi_dboid,
17411747
worker->wi_tableoid,worker->wi_cost_limit,worker->wi_cost_delay);
17421748
}
17431749

@@ -2062,25 +2068,27 @@ do_autovacuum(void)
20622068
VacuumCostDelay=tab->at_vacuum_cost_delay;
20632069
VacuumCostLimit=tab->at_vacuum_cost_limit;
20642070

2065-
/*
2066-
* Advertise my cost delay parameters for the balancing algorithm, and
2067-
* do a balance
2068-
*/
2071+
/* Last fixups before actually starting to work */
20692072
LWLockAcquire(AutovacuumLock,LW_EXCLUSIVE);
2073+
2074+
/* advertise my cost delay parameters for the balancing algorithm */
20702075
MyWorkerInfo->wi_cost_delay=tab->at_vacuum_cost_delay;
20712076
MyWorkerInfo->wi_cost_limit=tab->at_vacuum_cost_limit;
20722077
MyWorkerInfo->wi_cost_limit_base=tab->at_vacuum_cost_limit;
2078+
2079+
/* do a balance */
20732080
autovac_balance_cost();
2081+
2082+
/* done */
20742083
LWLockRelease(AutovacuumLock);
20752084

20762085
/* clean up memory before each iteration */
20772086
MemoryContextResetAndDeleteChildren(PortalContext);
20782087

20792088
/*
2080-
* We will abort vacuuming the current table if we are interrupted, and
2081-
* continue with the next one in schedule; but if anything else
2082-
* happens, we will do our usual error handling which is to cause the
2083-
* worker process to exit.
2089+
* We will abort vacuuming the current table if something errors out,
2090+
* and continue with the next one in schedule; in particular, this
2091+
* happens if we are interrupted with SIGINT.
20842092
*/
20852093
PG_TRY();
20862094
{
@@ -2094,39 +2102,40 @@ do_autovacuum(void)
20942102
}
20952103
PG_CATCH();
20962104
{
2097-
ErrorData*errdata;
2098-
2099-
MemoryContextSwitchTo(TopTransactionContext);
2100-
errdata=CopyErrorData();
2101-
21022105
/*
2103-
* If we errored out due to a cancel request, abort and restart the
2104-
* transaction and go to the next table. Otherwise rethrow the
2105-
* error so that the outermost handler deals with it.
2106+
* Abort the transaction, start a new one, and proceed with the
2107+
* next table in our list.
21062108
*/
2107-
if (errdata->sqlerrcode==ERRCODE_QUERY_CANCELED)
2108-
{
2109-
HOLD_INTERRUPTS();
2110-
elog(LOG,"cancelling autovacuum of table \"%s.%s.%s\"",
2111-
get_database_name(MyDatabaseId),
2112-
get_namespace_name(get_rel_namespace(tab->at_relid)),
2113-
get_rel_name(tab->at_relid));
2114-
2115-
AbortOutOfAnyTransaction();
2116-
FlushErrorState();
2117-
MemoryContextResetAndDeleteChildren(PortalContext);
2118-
2119-
/* restart our transaction for the following operations */
2120-
StartTransactionCommand();
2121-
RESUME_INTERRUPTS();
2122-
}
2109+
HOLD_INTERRUPTS();
2110+
if (tab->at_dovacuum)
2111+
errcontext("automatic vacuum of table \"%s.%s.%s\"",
2112+
get_database_name(MyDatabaseId),
2113+
get_namespace_name(get_rel_namespace(tab->at_relid)),
2114+
get_rel_name(tab->at_relid));
21232115
else
2124-
PG_RE_THROW();
2116+
errcontext("automatic analyze of table \"%s.%s.%s\"",
2117+
get_database_name(MyDatabaseId),
2118+
get_namespace_name(get_rel_namespace(tab->at_relid)),
2119+
get_rel_name(tab->at_relid));
2120+
EmitErrorReport();
2121+
2122+
AbortOutOfAnyTransaction();
2123+
FlushErrorState();
2124+
MemoryContextResetAndDeleteChildren(PortalContext);
2125+
2126+
/* restart our transaction for the following operations */
2127+
StartTransactionCommand();
2128+
RESUME_INTERRUPTS();
21252129
}
21262130
PG_END_TRY();
21272131

21282132
/* be tidy */
21292133
pfree(tab);
2134+
2135+
/* remove my info from shared memory */
2136+
LWLockAcquire(AutovacuumLock,LW_EXCLUSIVE);
2137+
MyWorkerInfo->wi_tableoid=InvalidOid;
2138+
LWLockRelease(AutovacuumLock);
21302139
}
21312140

21322141
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp