mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-21 08:29:39 +08:00
e5d8a99903
Otherwise we risk "leaking" deleted pages by making them non-recyclable indefinitely. Commit6655a729
did 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
138 lines
3.3 KiB
SQL
138 lines
3.3 KiB
SQL
/* contrib/pageinspect/pageinspect--1.8--1.9.sql */
|
|
|
|
-- complain if script is sourced in psql, rather than via ALTER EXTENSION
|
|
\echo Use "ALTER EXTENSION pageinspect UPDATE TO '1.9'" to load this file. \quit
|
|
|
|
--
|
|
-- gist_page_opaque_info()
|
|
--
|
|
CREATE FUNCTION gist_page_opaque_info(IN page bytea,
|
|
OUT lsn pg_lsn,
|
|
OUT nsn pg_lsn,
|
|
OUT rightlink bigint,
|
|
OUT flags text[])
|
|
AS 'MODULE_PATHNAME', 'gist_page_opaque_info'
|
|
LANGUAGE C STRICT PARALLEL SAFE;
|
|
|
|
|
|
--
|
|
-- gist_page_items_bytea()
|
|
--
|
|
CREATE FUNCTION gist_page_items_bytea(IN page bytea,
|
|
OUT itemoffset smallint,
|
|
OUT ctid tid,
|
|
OUT itemlen smallint,
|
|
OUT dead boolean,
|
|
OUT key_data bytea)
|
|
RETURNS SETOF record
|
|
AS 'MODULE_PATHNAME', 'gist_page_items_bytea'
|
|
LANGUAGE C STRICT PARALLEL SAFE;
|
|
|
|
--
|
|
-- gist_page_items()
|
|
--
|
|
CREATE FUNCTION gist_page_items(IN page bytea,
|
|
IN index_oid regclass,
|
|
OUT itemoffset smallint,
|
|
OUT ctid tid,
|
|
OUT itemlen smallint,
|
|
OUT dead boolean,
|
|
OUT keys text)
|
|
RETURNS SETOF record
|
|
AS 'MODULE_PATHNAME', 'gist_page_items'
|
|
LANGUAGE C STRICT PARALLEL SAFE;
|
|
|
|
--
|
|
-- get_raw_page()
|
|
--
|
|
DROP FUNCTION get_raw_page(text, int4);
|
|
CREATE FUNCTION get_raw_page(text, int8)
|
|
RETURNS bytea
|
|
AS 'MODULE_PATHNAME', 'get_raw_page_1_9'
|
|
LANGUAGE C STRICT PARALLEL SAFE;
|
|
|
|
DROP FUNCTION get_raw_page(text, text, int4);
|
|
CREATE FUNCTION get_raw_page(text, text, int8)
|
|
RETURNS bytea
|
|
AS 'MODULE_PATHNAME', 'get_raw_page_fork_1_9'
|
|
LANGUAGE C STRICT PARALLEL SAFE;
|
|
|
|
--
|
|
-- page_checksum()
|
|
--
|
|
DROP FUNCTION page_checksum(IN page bytea, IN blkno int4);
|
|
CREATE FUNCTION page_checksum(IN page bytea, IN blkno int8)
|
|
RETURNS smallint
|
|
AS 'MODULE_PATHNAME', 'page_checksum_1_9'
|
|
LANGUAGE C STRICT PARALLEL SAFE;
|
|
|
|
--
|
|
-- bt_metap()
|
|
--
|
|
DROP FUNCTION bt_metap(text);
|
|
CREATE FUNCTION bt_metap(IN relname text,
|
|
OUT magic int4,
|
|
OUT version int4,
|
|
OUT root int8,
|
|
OUT level int8,
|
|
OUT fastroot int8,
|
|
OUT fastlevel int8,
|
|
OUT last_cleanup_num_delpages int8,
|
|
OUT last_cleanup_num_tuples float8,
|
|
OUT allequalimage boolean)
|
|
AS 'MODULE_PATHNAME', 'bt_metap'
|
|
LANGUAGE C STRICT PARALLEL SAFE;
|
|
|
|
--
|
|
-- bt_page_stats()
|
|
--
|
|
DROP FUNCTION bt_page_stats(text, int4);
|
|
CREATE FUNCTION bt_page_stats(IN relname text, IN blkno int8,
|
|
OUT blkno int8,
|
|
OUT type "char",
|
|
OUT live_items int4,
|
|
OUT dead_items int4,
|
|
OUT avg_item_size int4,
|
|
OUT page_size int4,
|
|
OUT free_size int4,
|
|
OUT btpo_prev int8,
|
|
OUT btpo_next int8,
|
|
OUT btpo_level int8,
|
|
OUT btpo_flags int4)
|
|
AS 'MODULE_PATHNAME', 'bt_page_stats_1_9'
|
|
LANGUAGE C STRICT PARALLEL SAFE;
|
|
|
|
--
|
|
-- bt_page_items()
|
|
--
|
|
DROP FUNCTION bt_page_items(text, int4);
|
|
CREATE FUNCTION bt_page_items(IN relname text, IN blkno int8,
|
|
OUT itemoffset smallint,
|
|
OUT ctid tid,
|
|
OUT itemlen smallint,
|
|
OUT nulls bool,
|
|
OUT vars bool,
|
|
OUT data text,
|
|
OUT dead boolean,
|
|
OUT htid tid,
|
|
OUT tids tid[])
|
|
RETURNS SETOF record
|
|
AS 'MODULE_PATHNAME', 'bt_page_items_1_9'
|
|
LANGUAGE C STRICT PARALLEL SAFE;
|
|
|
|
--
|
|
-- brin_page_items()
|
|
--
|
|
DROP FUNCTION brin_page_items(IN page bytea, IN index_oid regclass);
|
|
CREATE FUNCTION brin_page_items(IN page bytea, IN index_oid regclass,
|
|
OUT itemoffset int,
|
|
OUT blknum int8,
|
|
OUT attnum int,
|
|
OUT allnulls bool,
|
|
OUT hasnulls bool,
|
|
OUT placeholder bool,
|
|
OUT value text)
|
|
RETURNS SETOF record
|
|
AS 'MODULE_PATHNAME', 'brin_page_items'
|
|
LANGUAGE C STRICT PARALLEL SAFE;
|