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

Commit2751c7f

Browse files
committed
Ensure ANALYZE phase is not skipped because of canceled truncate.
Patchb19e425 attempted topreserve existing behavior regarding statistics generation in thecase that a truncation attempt was canceled due to lock conflicts.It failed to do this accurately in two regards: (1) autovacuum hadpreviously generated statistics if the truncate attempt failed toinitially get the lock rather than having started the attempt, and(2) the VACUUM ANALYZE command had always generated statistics.Both of these changes were unintended, and are reverted by thispatch. On review, there seems to be consensus that the previousfailure to generate statistics when the truncate was terminatedwas more an unfortunate consequence of how that effort waspreviously terminated than a feature we want to keep; so thispatch generates statistics even when an autovacuum truncationattempt terminates early. Another unintended change which is kepton the basis that it is an improvement is that when a VACUUMcommand is truncating, it will the new heuristic for avoidingblocking other processes, rather than keeping anAccessExclusiveLock on the table for however long the truncationtakes.Per multiple reports, with some renaming per patch by Jeff Janes.Backpatch to 9.0, where problem was created.
1 parent0dcff75 commit2751c7f

File tree

1 file changed

+22
-36
lines changed

1 file changed

+22
-36
lines changed

‎src/backend/commands/vacuumlazy.c

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@
7474
* that the potential for improvement was great enough to merit the cost of
7575
* supporting them.
7676
*/
77-
#defineAUTOVACUUM_TRUNCATE_LOCK_CHECK_INTERVAL20/* ms */
78-
#defineAUTOVACUUM_TRUNCATE_LOCK_WAIT_INTERVAL50/* ms */
79-
#defineAUTOVACUUM_TRUNCATE_LOCK_TIMEOUT5000/* ms */
77+
#defineVACUUM_TRUNCATE_LOCK_CHECK_INTERVAL20/* ms */
78+
#defineVACUUM_TRUNCATE_LOCK_WAIT_INTERVAL50/* ms */
79+
#defineVACUUM_TRUNCATE_LOCK_TIMEOUT5000/* ms */
8080

8181
/*
8282
* Guesstimation of number of dead tuples per page. This is used to
@@ -254,17 +254,10 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
254254
vacrelstats->hasindex,
255255
new_frozen_xid);
256256

257-
/*
258-
* Report results to the stats collector, too. An early terminated
259-
* lazy_truncate_heap attempt suppresses the message and also cancels the
260-
* execution of ANALYZE, if that was ordered.
261-
*/
262-
if (!vacrelstats->lock_waiter_detected)
263-
pgstat_report_vacuum(RelationGetRelid(onerel),
264-
onerel->rd_rel->relisshared,
265-
new_rel_tuples);
266-
else
267-
vacstmt->options &= ~VACOPT_ANALYZE;
257+
/* report results to the stats collector, too */
258+
pgstat_report_vacuum(RelationGetRelid(onerel),
259+
onerel->rd_rel->relisshared,
260+
new_rel_tuples);
268261

269262
/* and log the action if appropriate */
270263
if (IsAutoVacuumWorkerProcess()&&Log_autovacuum_min_duration >=0)
@@ -1138,28 +1131,21 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats)
11381131
*/
11391132
CHECK_FOR_INTERRUPTS();
11401133

1141-
if (++lock_retry> (AUTOVACUUM_TRUNCATE_LOCK_TIMEOUT /
1142-
AUTOVACUUM_TRUNCATE_LOCK_WAIT_INTERVAL))
1134+
if (++lock_retry> (VACUUM_TRUNCATE_LOCK_TIMEOUT /
1135+
VACUUM_TRUNCATE_LOCK_WAIT_INTERVAL))
11431136
{
11441137
/*
11451138
* We failed to establish the lock in the specified number of
1146-
* retries. This means we give up truncating. Suppress the
1147-
* ANALYZE step. Doing an ANALYZE at this point will reset the
1148-
* dead_tuple_count in the stats collector, so we will not get
1149-
* called by the autovacuum launcher again to do the truncate.
1139+
* retries. This means we give up truncating.
11501140
*/
11511141
vacrelstats->lock_waiter_detected= true;
1152-
ereport(LOG,
1153-
(errmsg("automatic vacuum of table \"%s.%s.%s\": "
1154-
"could not (re)acquire exclusive "
1155-
"lock for truncate scan",
1156-
get_database_name(MyDatabaseId),
1157-
get_namespace_name(RelationGetNamespace(onerel)),
1142+
ereport(elevel,
1143+
(errmsg("\"%s\": stopping truncate due to conflicting lock request",
11581144
RelationGetRelationName(onerel))));
11591145
return;
11601146
}
11611147

1162-
pg_usleep(AUTOVACUUM_TRUNCATE_LOCK_WAIT_INTERVAL);
1148+
pg_usleep(VACUUM_TRUNCATE_LOCK_WAIT_INTERVAL);
11631149
}
11641150

11651151
/*
@@ -1239,8 +1225,6 @@ count_nondeletable_pages(Relation onerel, LVRelStats *vacrelstats)
12391225
{
12401226
BlockNumberblkno;
12411227
instr_timestarttime;
1242-
instr_timecurrenttime;
1243-
instr_timeelapsed;
12441228

12451229
/* Initialize the starttime if we check for conflicting lock requests */
12461230
INSTR_TIME_SET_CURRENT(starttime);
@@ -1258,24 +1242,26 @@ count_nondeletable_pages(Relation onerel, LVRelStats *vacrelstats)
12581242
/*
12591243
* Check if another process requests a lock on our relation. We are
12601244
* holding an AccessExclusiveLock here, so they will be waiting. We
1261-
* only do thisin autovacuum_truncate_lock_check millisecond
1262-
*intervals, and weonly check if that interval has elapsed once
1263-
*every 32 blocks tokeep the number of system calls and actual
1264-
*shared lock tablelookups to a minimum.
1245+
* only do thisonce per VACUUM_TRUNCATE_LOCK_CHECK_INTERVAL, and we
1246+
* only check if that interval has elapsed once every 32 blocks to
1247+
* keep the number of system calls and actual shared lock table
1248+
* lookups to a minimum.
12651249
*/
12661250
if ((blkno %32)==0)
12671251
{
1252+
instr_timecurrenttime;
1253+
instr_timeelapsed;
1254+
12681255
INSTR_TIME_SET_CURRENT(currenttime);
12691256
elapsed=currenttime;
12701257
INSTR_TIME_SUBTRACT(elapsed,starttime);
12711258
if ((INSTR_TIME_GET_MICROSEC(elapsed) /1000)
1272-
>=AUTOVACUUM_TRUNCATE_LOCK_CHECK_INTERVAL)
1259+
>=VACUUM_TRUNCATE_LOCK_CHECK_INTERVAL)
12731260
{
12741261
if (LockHasWaitersRelation(onerel,AccessExclusiveLock))
12751262
{
12761263
ereport(elevel,
1277-
(errmsg("\"%s\": suspending truncate "
1278-
"due to conflicting lock request",
1264+
(errmsg("\"%s\": suspending truncate due to conflicting lock request",
12791265
RelationGetRelationName(onerel))));
12801266

12811267
vacrelstats->lock_waiter_detected= true;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp