mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +03:00
Use full 64-bit XIDs in deleted nbtree pages.
Otherwise we risk "leaking" deleted pages by making them non-recyclable indefinitely. Commit6655a729did the same thing for deleted pages in GiST indexes. That work was used as a starting point here. Stop storing an XID indicating the oldest bpto.xact across all deleted though unrecycled pages in nbtree metapages. There is no longer any reason to care about that condition/the oldest XID. It only ever made sense when wraparound was something _bt_vacuum_needs_cleanup() had to consider. The btm_oldest_btpo_xact metapage field has been repurposed and renamed. It is now btm_last_cleanup_num_delpages, which is used to remember how many non-recycled deleted pages remain from the last VACUUM (in practice its value is usually the precise number of pages that were _newly deleted_ during the specific VACUUM operation that last set the field). The general idea behind storing btm_last_cleanup_num_delpages is to use it to give _some_ consideration to non-recycled deleted pages inside _bt_vacuum_needs_cleanup() -- though never too much. We only really need to avoid leaving a truly excessive number of deleted pages in an unrecycled state forever. We only do this to cover certain narrow cases where no other factor makes VACUUM do a full scan, and yet the index continues to grow (and so actually misses out on recycling existing deleted pages). These metapage changes result in a clear user-visible benefit: We no longer trigger full index scans during VACUUM operations solely due to the presence of only 1 or 2 known deleted (though unrecycled) blocks from a very large index. All that matters now is keeping the costs and benefits in balance over time. Fix an issue that has been around since commit857f9c36, which added the "skip full scan of index" mechanism (i.e. the _bt_vacuum_needs_cleanup() logic). The accuracy of btm_last_cleanup_num_heap_tuples accidentally hinged upon _when_ the source value gets stored. We now always store btm_last_cleanup_num_heap_tuples in btvacuumcleanup(). This fixes the issue because IndexVacuumInfo.num_heap_tuples (the source field) is expected to accurately indicate the state of the table _after_ the VACUUM completes inside btvacuumcleanup(). A backpatchable fix cannot easily be extracted from this commit. A targeted fix for the issue will follow in a later commit, though that won't happen today. I (pgeoghegan) have chosen to remove any mention of deleted pages in the documentation of the vacuum_cleanup_index_scale_factor GUC/param, since the presence of deleted (though unrecycled) pages is no longer of much concern to users. The vacuum_cleanup_index_scale_factor description in the docs now seems rather unclear in any case, and it should probably be rewritten in the near future. Perhaps some passing mention of page deletion will be added back at the same time. Bump XLOG_PAGE_MAGIC due to nbtree WAL records using full XIDs now. Author: Peter Geoghegan <pg@bowt.ie> Reviewed-By: Masahiko Sawada <sawada.mshk@gmail.com> Discussion: https://postgr.es/m/CAH2-WznpdHvujGUwYZ8sihX=d5u-tRYhi-F4wnV2uN2zHpMUXw@mail.gmail.com
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#ifndef NBTXLOG_H
|
||||
#define NBTXLOG_H
|
||||
|
||||
#include "access/transam.h"
|
||||
#include "access/xlogreader.h"
|
||||
#include "lib/stringinfo.h"
|
||||
#include "storage/off.h"
|
||||
@@ -52,7 +53,7 @@ typedef struct xl_btree_metadata
|
||||
uint32 level;
|
||||
BlockNumber fastroot;
|
||||
uint32 fastlevel;
|
||||
TransactionId oldest_btpo_xact;
|
||||
uint32 last_cleanup_num_delpages;
|
||||
float8 last_cleanup_num_heap_tuples;
|
||||
bool allequalimage;
|
||||
} xl_btree_metadata;
|
||||
@@ -187,7 +188,7 @@ typedef struct xl_btree_reuse_page
|
||||
{
|
||||
RelFileNode node;
|
||||
BlockNumber block;
|
||||
TransactionId latestRemovedXid;
|
||||
FullTransactionId latestRemovedFullXid;
|
||||
} xl_btree_reuse_page;
|
||||
|
||||
#define SizeOfBtreeReusePage (sizeof(xl_btree_reuse_page))
|
||||
@@ -282,9 +283,12 @@ typedef struct xl_btree_mark_page_halfdead
|
||||
#define SizeOfBtreeMarkPageHalfDead (offsetof(xl_btree_mark_page_halfdead, topparent) + sizeof(BlockNumber))
|
||||
|
||||
/*
|
||||
* This is what we need to know about deletion of a btree page. Note we do
|
||||
* not store any content for the deleted page --- it is just rewritten as empty
|
||||
* during recovery, apart from resetting the btpo.xact.
|
||||
* This is what we need to know about deletion of a btree page. Note that we
|
||||
* only leave behind a small amount of bookkeeping information in deleted
|
||||
* pages (deleted pages must be kept around as tombstones for a while). It is
|
||||
* convenient for the REDO routine to regenerate its target page from scratch.
|
||||
* This is why WAL record describes certain details that are actually directly
|
||||
* available from the target page.
|
||||
*
|
||||
* Backup Blk 0: target block being deleted
|
||||
* Backup Blk 1: target block's left sibling, if any
|
||||
@@ -296,20 +300,24 @@ typedef struct xl_btree_unlink_page
|
||||
{
|
||||
BlockNumber leftsib; /* target block's left sibling, if any */
|
||||
BlockNumber rightsib; /* target block's right sibling */
|
||||
uint32 level; /* target block's level */
|
||||
FullTransactionId safexid; /* target block's BTPageSetDeleted() XID */
|
||||
|
||||
/*
|
||||
* Information needed to recreate the leaf page, when target is an
|
||||
* internal page.
|
||||
* Information needed to recreate a half-dead leaf page with correct
|
||||
* topparent link. The fields are only used when deletion operation's
|
||||
* target page is an internal page. REDO routine creates half-dead page
|
||||
* from scratch to keep things simple (this is the same convenient
|
||||
* approach used for the target page itself).
|
||||
*/
|
||||
BlockNumber leafleftsib;
|
||||
BlockNumber leafrightsib;
|
||||
BlockNumber topparent; /* next child down in the subtree */
|
||||
BlockNumber leaftopparent; /* next child down in the subtree */
|
||||
|
||||
TransactionId btpo_xact; /* value of btpo.xact for use in recovery */
|
||||
/* xl_btree_metadata FOLLOWS IF XLOG_BTREE_UNLINK_PAGE_META */
|
||||
} xl_btree_unlink_page;
|
||||
|
||||
#define SizeOfBtreeUnlinkPage (offsetof(xl_btree_unlink_page, btpo_xact) + sizeof(TransactionId))
|
||||
#define SizeOfBtreeUnlinkPage (offsetof(xl_btree_unlink_page, leaftopparent) + sizeof(BlockNumber))
|
||||
|
||||
/*
|
||||
* New root log record. There are zero tuples if this is to establish an
|
||||
|
||||
Reference in New Issue
Block a user