]> granicus.if.org Git - postgresql/commitdiff
Log when a BRIN autosummarization request fails
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 14 Mar 2018 14:53:56 +0000 (11:53 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 14 Mar 2018 15:00:53 +0000 (12:00 -0300)
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

doc/src/sgml/brin.sgml
src/backend/access/brin/brin.c
src/backend/postmaster/autovacuum.c
src/include/postmaster/autovacuum.h

index 8dcc29925bc9ac192fe14ab68a28afbb6eda5f0a..8aef786778f37528a640eab21d9f6fc32af62b9a 100644 (file)
    representation because the existing values have changed.
   </para>
 
+  <para>
+   When autosummarization is enabled, each time a page range is filled a
+   request is sent to autovacuum for it to execute a targeted summarization
+   for that range, to be fulfilled at the end of the next worker run on the
+   same database.  If the request queue is full, the request is not recorded
+   and a message is sent to the server log:
+<screen>
+LOG:  request for BRIN range summarization for index "brin_wi_idx" page 128 was not recorded
+</screen>
+   When this happens, the range will be summarized normally during the next
+   regular vacuum of the table.
+  </para>
  </sect2>
 </sect1>
 
index 4f0ff79cb49e95be182b8f2ba51a4e4c6af07ac0..7f4600f18d6849369dd5c44e4fc2a5479cbadf9b 100644 (file)
@@ -187,9 +187,19 @@ brininsert(Relation idxRel, Datum *values, bool *nulls,
                                brinGetTupleForHeapBlock(revmap, lastPageRange, &buf, &off,
                                                                                 NULL, BUFFER_LOCK_SHARE, NULL);
                        if (!lastPageTuple)
-                               AutoVacuumRequestWork(AVW_BRINSummarizeRange,
-                                                                         RelationGetRelid(idxRel),
-                                                                         lastPageRange);
+                       {
+                               bool    recorded;
+
+                               recorded = AutoVacuumRequestWork(AVW_BRINSummarizeRange,
+                                                                                                RelationGetRelid(idxRel),
+                                                                                                lastPageRange);
+                               if (!recorded)
+                                       ereport(LOG,
+                                                       (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+                                                        errmsg("request for BRIN range summarization for index \"%s\" page %u was not recorded",
+                                                                       RelationGetRelationName(idxRel),
+                                                                       lastPageRange)));
+                       }
                        else
                                LockBuffer(buf, BUFFER_LOCK_UNLOCK);
                }
index ec2de9d9a399bce8894e73af6e77d2d2f2946759..70e08b552a1566c000bf337050bd2cba7beeb581 100644 (file)
@@ -3227,12 +3227,14 @@ AutoVacuumingActive(void)
 
 /*
  * Request one work item to the next autovacuum run processing our database.
+ * Return false if the request can't be recorded.
  */
-void
+bool
 AutoVacuumRequestWork(AutoVacuumWorkItemType type, Oid relationId,
                                          BlockNumber blkno)
 {
        int                     i;
+       bool            result = false;
 
        LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
 
@@ -3252,12 +3254,15 @@ AutoVacuumRequestWork(AutoVacuumWorkItemType type, Oid relationId,
                workitem->avw_database = MyDatabaseId;
                workitem->avw_relation = relationId;
                workitem->avw_blockNumber = blkno;
+               result = true;
 
                /* done */
                break;
        }
 
        LWLockRelease(AutovacuumLock);
+
+       return result;
 }
 
 /*
index 3469915ae25c11ce0ec1c776d59fda0714d993c8..816f031c011578d17aa03a3bf55aa32bc4963e56 100644 (file)
@@ -71,7 +71,7 @@ extern void AutovacuumWorkerIAm(void);
 extern void AutovacuumLauncherIAm(void);
 #endif
 
-extern void AutoVacuumRequestWork(AutoVacuumWorkItemType type,
+extern bool AutoVacuumRequestWork(AutoVacuumWorkItemType type,
                                          Oid relationId, BlockNumber blkno);
 
 /* shared memory stuff */