Skip to content

Commit 484a4a0

Browse files
committed
Log when a BRIN autosummarization request fails
Autovacuum's 'workitem' request queue is of limited size, so requests can fail if they arrive more quickly than autovacuum can process them. Emit a log message when this happens, to provide better visibility of this. Backpatch to 10. While this represents an API change for AutoVacuumRequestWork, that function is not yet prepared to deal with external modules calling it, so there doesn't seem to be any risk (other than log spam, that is.) Author: Masahiko Sawada Reviewed-by: Fabrízio Mello, Ildar Musin, Álvaro Herrera Discussion: https://postgr.es/m/CAD21AoB1HrQhp6_4rTyHN5kWEJCEsG8YzsjZNt-ctoXSn5Uisw@mail.gmail.com
1 parent 97d18ce commit 484a4a0

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

doc/src/sgml/brin.sgml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@
8686
representation because the existing values have changed.
8787
</para>
8888

89+
<para>
90+
When autosummarization is enabled, each time a page range is filled a
91+
request is sent to autovacuum for it to execute a targeted summarization
92+
for that range, to be fulfilled at the end of the next worker run on the
93+
same database. If the request queue is full, the request is not recorded
94+
and a message is sent to the server log:
95+
<screen>
96+
LOG: request for BRIN range summarization for index "brin_wi_idx" page 128 was not recorded
97+
</screen>
98+
When this happens, the range will be summarized normally during the next
99+
regular vacuum of the table.
100+
</para>
89101
</sect2>
90102
</sect1>
91103

src/backend/access/brin/brin.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,19 @@ brininsert(Relation idxRel, Datum *values, bool *nulls,
187187
brinGetTupleForHeapBlock(revmap, lastPageRange, &buf, &off,
188188
NULL, BUFFER_LOCK_SHARE, NULL);
189189
if (!lastPageTuple)
190-
AutoVacuumRequestWork(AVW_BRINSummarizeRange,
191-
RelationGetRelid(idxRel),
192-
lastPageRange);
190+
{
191+
bool recorded;
192+
193+
recorded = AutoVacuumRequestWork(AVW_BRINSummarizeRange,
194+
RelationGetRelid(idxRel),
195+
lastPageRange);
196+
if (!recorded)
197+
ereport(LOG,
198+
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
199+
errmsg("request for BRIN range summarization for index \"%s\" page %u was not recorded",
200+
RelationGetRelationName(idxRel),
201+
lastPageRange)));
202+
}
193203
else
194204
LockBuffer(buf, BUFFER_LOCK_UNLOCK);
195205
}

src/backend/postmaster/autovacuum.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3227,12 +3227,14 @@ AutoVacuumingActive(void)
32273227

32283228
/*
32293229
* Request one work item to the next autovacuum run processing our database.
3230+
* Return false if the request can't be recorded.
32303231
*/
3231-
void
3232+
bool
32323233
AutoVacuumRequestWork(AutoVacuumWorkItemType type, Oid relationId,
32333234
BlockNumber blkno)
32343235
{
32353236
int i;
3237+
bool result = false;
32363238

32373239
LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
32383240

@@ -3252,12 +3254,15 @@ AutoVacuumRequestWork(AutoVacuumWorkItemType type, Oid relationId,
32523254
workitem->avw_database = MyDatabaseId;
32533255
workitem->avw_relation = relationId;
32543256
workitem->avw_blockNumber = blkno;
3257+
result = true;
32553258

32563259
/* done */
32573260
break;
32583261
}
32593262

32603263
LWLockRelease(AutovacuumLock);
3264+
3265+
return result;
32613266
}
32623267

32633268
/*

src/include/postmaster/autovacuum.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ extern void AutovacuumWorkerIAm(void);
7171
extern void AutovacuumLauncherIAm(void);
7272
#endif
7373

74-
extern void AutoVacuumRequestWork(AutoVacuumWorkItemType type,
74+
extern bool AutoVacuumRequestWork(AutoVacuumWorkItemType type,
7575
Oid relationId, BlockNumber blkno);
7676

7777
/* shared memory stuff */

0 commit comments

Comments
 (0)