Optionally prefetch referenced data in recovery.
authorThomas Munro <tmunro@postgresql.org>
Thu, 8 Apr 2021 11:03:43 +0000 (23:03 +1200)
committerThomas Munro <tmunro@postgresql.org>
Thu, 8 Apr 2021 11:20:42 +0000 (23:20 +1200)
commit1d257577e08d3e598011d6850fd1025858de8c8c
tree1c2ac92489fe1e54cdc0837dec9b84d17434c4b7
parentf003d9f8721b3249e4aec8a1946034579d40d42c
Optionally prefetch referenced data in recovery.

Introduce a new GUC recovery_prefetch, disabled by default.  When
enabled, look ahead in the WAL and try to initiate asynchronous reading
of referenced data blocks that are not yet cached in our buffer pool.
For now, this is done with posix_fadvise(), which has several caveats.
Better mechanisms will follow in later work on the I/O subsystem.

The GUC maintenance_io_concurrency is used to limit the number of
concurrent I/Os we allow ourselves to initiate, based on pessimistic
heuristics used to infer that I/Os have begun and completed.

The GUC wal_decode_buffer_size is used to limit the maximum distance we
are prepared to read ahead in the WAL to find uncached blocks.

Reviewed-by: Alvaro Herrera <alvherre@2ndquadrant.com> (parts)
Reviewed-by: Andres Freund <andres@anarazel.de> (parts)
Reviewed-by: Tomas Vondra <tomas.vondra@2ndquadrant.com> (parts)
Tested-by: Tomas Vondra <tomas.vondra@2ndquadrant.com>
Tested-by: Jakub Wartak <Jakub.Wartak@tomtom.com>
Tested-by: Dmitry Dolgov <9erthalion6@gmail.com>
Tested-by: Sait Talha Nisanci <Sait.Nisanci@microsoft.com>
Discussion: https://postgr.es/m/CA%2BhUKGJ4VJN8ttxScUFM8dOKX0BrBiboo5uz1cq%3DAovOddfHpA%40mail.gmail.com
23 files changed:
doc/src/sgml/config.sgml
doc/src/sgml/monitoring.sgml
doc/src/sgml/wal.sgml
src/backend/access/transam/Makefile
src/backend/access/transam/xlog.c
src/backend/access/transam/xlogprefetch.c [new file with mode: 0644]
src/backend/access/transam/xlogreader.c
src/backend/access/transam/xlogutils.c
src/backend/catalog/system_views.sql
src/backend/postmaster/pgstat.c
src/backend/storage/freespace/freespace.c
src/backend/storage/ipc/ipci.c
src/backend/utils/misc/guc.c
src/backend/utils/misc/postgresql.conf.sample
src/include/access/xlog.h
src/include/access/xlogprefetch.h [new file with mode: 0644]
src/include/access/xlogreader.h
src/include/access/xlogutils.h
src/include/catalog/pg_proc.dat
src/include/pgstat.h
src/include/utils/guc.h
src/test/regress/expected/rules.out
src/tools/pgindent/typedefs.list