pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Compute XID horizon for page level index vacuum on primary.
Date: Wed, 27 Mar 2019 00:06:45 +0000
Message-ID: <E1h8w5d-0006c7-16@gemulon.postgresql.org> (raw)

Compute XID horizon for page level index vacuum on primary.

Previously the xid horizon was only computed during WAL replay. That
had two major problems:
1) It relied on knowing what the table pointed to looks like. That was
   easy enough before the introducing of tableam (we knew it had to be
   heap, although some trickery around logging the heap relfilenodes
   was required). But to properly handle table AMs we need
   per-database catalog access to look up the AM handler, which
   recovery doesn't allow.
2) Not knowing the xid horizon also makes it hard to support logical
   decoding on standbys. When on a catalog table, we need to be able
   to conflict with slots that have an xid horizon that's too old. But
   computing the horizon by visiting the heap only works once
   consistency is reached, but we always need to be able to detect
   conflicts.

There's also a secondary problem, in that the current method performs
redundant work on every standby. But that's counterbalanced by
potentially computing the value when not necessary (either because
there's no standby, or because there's no connected backends).

Solve 1) and 2) by moving computation of the xid horizon to the
primary and by involving tableam in the computation of the horizon.

To address the potentially increased overhead, increase the efficiency
of the xid horizon computation for heap by sorting the tids, and
eliminating redundant buffer accesses. When prefetching is available,
additionally perform prefetching of buffers.  As this is more of a
maintenance task, rather than something routinely done in every read
only query, we add an arbitrary 10 to the effective concurrency -
thereby using IO concurrency, when not globally enabled.  That's
possibly not the perfect formula, but seems good enough for now.

Bumps WAL format, as latestRemovedXid is now part of the records, and
the heap's relfilenode isn't anymore.

Author: Andres Freund, Amit Khandekar, Robert Haas
Reviewed-By: Robert Haas
Discussion:
    https://postgr.es/m/20181212204154.nsxf3gzqv3gesl32@alap3.anarazel.de
    https://postgr.es/m/20181214014235.dal5ogljs3bmlq44@alap3.anarazel.de
    https://postgr.es/m/20180703070645.wchpu5muyto5n647@alap3.anarazel.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/558a9165e081d1936573e5a7d576f5febd7fb55a

Modified Files
--------------
src/backend/access/hash/hash_xlog.c      | 153 +--------------------
src/backend/access/hash/hashinsert.c     |  17 ++-
src/backend/access/heap/heapam.c         | 221 +++++++++++++++++++++++++++++++
src/backend/access/heap/heapam_handler.c |   1 +
src/backend/access/index/genam.c         |  37 ++++++
src/backend/access/nbtree/nbtpage.c      |   8 +-
src/backend/access/nbtree/nbtxlog.c      | 156 +---------------------
src/backend/access/rmgrdesc/hashdesc.c   |   5 +-
src/backend/access/rmgrdesc/nbtdesc.c    |   3 +-
src/include/access/genam.h               |   5 +
src/include/access/hash_xlog.h           |   2 +-
src/include/access/heapam.h              |   4 +
src/include/access/nbtxlog.h             |   3 +-
src/include/access/tableam.h             |  19 +++
src/include/access/xlog_internal.h       |   2 +-
src/tools/pgindent/typedefs.list         |   1 +
16 files changed, 316 insertions(+), 321 deletions(-)



view thread (30+ messages)  latest in thread

Message-ID: <E1h8w5d-0006c7-16@gemulon.postgresql.org>
Permalink:  ../E1h8w5d-0006c7-16@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1h8w5d-0006c7-16@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: andres@anarazel.de
  Subject: Re: pgsql: Compute XID horizon for page level index vacuum on primary.
  In-Reply-To: <E1h8w5d-0006c7-16@gemulon.postgresql.org>
  References: <E1h8w5d-0006c7-16@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox