postgresql_16:8.20.1.1 Index Maintenance
PostgreSQL 16 > Internals > BRIN Indexes > Introduction > Index Maintenance
At the time of creation, all existing heap pages are scanned and a summary index tuple is created for each range, including the possibly-incomplete range at the end. As new pages are filled with data, page ranges that are already summarized will cause the summary information to be updated with data from the new tuples. When a new page is created that does not fall within the last summarized range, the range that the new page belongs to does not automatically acquire a summary tuple; those tuples remain unsummarized until a summarization run is invoked later, creating the initial summary for that range.
There are several ways to trigger the initial summarization of a page range. If the table is vacuumed, either manually or by autovacuum (see postgresql_16:4.10.1.6), all existing unsummarized page ranges are summarized. Also, if the index's (see postgresql_16:7.1.67.2) parameter is enabled, which it isn't by default, whenever autovacuum runs in that database, summarization will occur for all unsummarized page ranges that have been filled, regardless of whether the table itself is processed by autovacuum; see below.
Lastly, the following functions can be used: brin_summarize_new_values(regclass) which summarizes all unsummarized ranges; brin_summarize_range(regclass, bigint) which summarizes only the range containing the given page, if it is unsummarized.
When autosummarization is enabled, a request is sent to autovacuum to execute a targeted summarization for a block range when an insertion is detected for the first item of the first page of the next block range, to be fulfilled the next time an autovacuum worker finishes running in the same database. If the request queue is full, the request is not recorded and a message is sent to the server log: LOG: request for BRIN range summarization for index "brin_wi_idx" page 128 was not recorded When this happens, the range will remain unsummarized until the next regular vacuum run on the table, or one of the functions mentioned above are invoked.
Conversely, a range can be de-summarized using the brin_desummarize_range(regclass, bigint) function, which is useful when the index tuple is no longer a very good representation because the existing values have changed. See (see postgresql_16:3.6.27.8) for details.