diff options
author | Teodor Sigaev <teodor@sigaev.ru> | 2018-04-04 19:29:00 +0300 |
---|---|---|
committer | Teodor Sigaev <teodor@sigaev.ru> | 2018-04-04 19:29:00 +0300 |
commit | 857f9c36cda520030381bd8c2af20adf0ce0e1d4 (patch) | |
tree | 3d896351d041c5745111e5ae5dc2c11177dfd31c /doc/src | |
parent | eac93e20afe434a79e81558c17a7a1408cf9d74a (diff) | |
download | postgresql-857f9c36cda520030381bd8c2af20adf0ce0e1d4.tar.gz postgresql-857f9c36cda520030381bd8c2af20adf0ce0e1d4.zip |
Skip full index scan during cleanup of B-tree indexes when possible
Vacuum of index consists from two stages: multiple (zero of more) ambulkdelete
calls and one amvacuumcleanup call. When workload on particular table
is append-only, then autovacuum isn't intended to touch this table. However,
user may run vacuum manually in order to fill visibility map and get benefits
of index-only scans. Then ambulkdelete wouldn't be called for indexes
of such table (because no heap tuples were deleted), only amvacuumcleanup would
be called In this case, amvacuumcleanup would perform full index scan for
two objectives: put recyclable pages into free space map and update index
statistics.
This patch allows btvacuumclanup to skip full index scan when two conditions
are satisfied: no pages are going to be put into free space map and index
statistics isn't stalled. In order to check first condition, we store
oldest btpo_xact in the meta-page. When it's precedes RecentGlobalXmin, then
there are some recyclable pages. In order to check second condition we store
number of heap tuples observed during previous full index scan by cleanup.
If fraction of newly inserted tuples is less than
vacuum_cleanup_index_scale_factor, then statistics isn't considered to be
stalled. vacuum_cleanup_index_scale_factor can be defined as both reloption and GUC (default).
This patch bumps B-tree meta-page version. Upgrade of meta-page is performed
"on the fly": during VACUUM meta-page is rewritten with new version. No special
handling in pg_upgrade is required.
Author: Masahiko Sawada, Alexander Korotkov
Review by: Peter Geoghegan, Kyotaro Horiguchi, Alexander Korotkov, Yura Sokolov
Discussion: https://www.postgresql.org/message-id/flat/CAD21AoAX+d2oD_nrd9O2YkpzHaFr=uQeGr9s1rKC3O4ENc568g@mail.gmail.com
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/config.sgml | 25 | ||||
-rw-r--r-- | doc/src/sgml/pageinspect.sgml | 16 | ||||
-rw-r--r-- | doc/src/sgml/ref/create_index.sgml | 15 |
3 files changed, 49 insertions, 7 deletions
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index e7d408824e2..a189a8efc3f 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -1882,6 +1882,31 @@ include_dir 'conf.d' </note> </sect2> + <sect2 id="runtime-config-index-vacuum"> + <title>Index Vacuum</title> + <variablelist> + <varlistentry id="guc-vacuum-cleanup-index-scale-factor" xreflabel="vacuum_cleanup_index_scale_factor"> + <term><varname>vacuum_cleanup_index_scale_factor</varname> (<type>floating point</type>) + <indexterm> + <primary><varname>vacuum_cleanup_index_scale_factor</varname> configuration parameter</primary> + </indexterm> + </term> + <listitem> + <para> + When no tuples were deleted from the heap, B-tree indexes might still + be scanned during <command>VACUUM</command> cleanup stage by two + reasons. The first reason is that B-tree index contains deleted pages + which can be recycled during cleanup. The second reason is that B-tree + index statistics is stalled. The criterion of stalled index statistics + is number of inserted tuples since previous statistics collection + is greater than <varname>vacuum_cleanup_index_scale_factor</varname> + fraction of total number of heap tuples. + </para> + </listitem> + </varlistentry> + </variablelist> + </sect2> + <sect2 id="runtime-config-resource-background-writer"> <title>Background Writer</title> diff --git a/doc/src/sgml/pageinspect.sgml b/doc/src/sgml/pageinspect.sgml index 23570af4bf8..4d5da186bb4 100644 --- a/doc/src/sgml/pageinspect.sgml +++ b/doc/src/sgml/pageinspect.sgml @@ -247,13 +247,15 @@ test=# SELECT * FROM heap_page_item_attrs(get_raw_page('pg_class', 0), 'pg_class index's metapage. For example: <screen> test=# SELECT * FROM bt_metap('pg_cast_oid_index'); --[ RECORD 1 ]----- -magic | 340322 -version | 2 -root | 1 -level | 0 -fastroot | 1 -fastlevel | 0 +-[ RECORD 1 ]-----------+------- +magic | 340322 +version | 3 +root | 1 +level | 0 +fastroot | 1 +fastlevel | 0 +oldest_xact | 582 +last_cleanup_num_tuples | 1000 </screen> </para> </listitem> diff --git a/doc/src/sgml/ref/create_index.sgml b/doc/src/sgml/ref/create_index.sgml index ba1c5d63925..e9521fbfb91 100644 --- a/doc/src/sgml/ref/create_index.sgml +++ b/doc/src/sgml/ref/create_index.sgml @@ -370,6 +370,21 @@ CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EXISTS ] <replaceable class= </variablelist> <para> + B-tree indexes additionally accept this parameter: + </para> + + <variablelist> + <varlistentry> + <term><literal>vacuum_cleanup_index_scale_factor</literal></term> + <listitem> + <para> + Per-table value for <xref linkend="guc-vacuum-cleanup-index-scale-factor"/>. + </para> + </listitem> + </varlistentry> + </variablelist> + + <para> GiST indexes additionally accept this parameter: </para> |