diff --git a/contrib/pageinspect/btreefuncs.c b/contrib/pageinspect/btreefuncs.c index dffb3e199b..e6a2fc1e15 100644 --- a/contrib/pageinspect/btreefuncs.c +++ b/contrib/pageinspect/btreefuncs.c @@ -597,6 +597,8 @@ bt_page_items_bytea(PG_FUNCTION_ARGS) } } +/* Number of output arguments (columns) for bt_metap() */ +#define BT_METAP_COLS_V1_8 9 /* ------------------------------------------------ * bt_metap() @@ -653,13 +655,30 @@ bt_metap(PG_FUNCTION_ARGS) if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); + /* + * We need a kluge here to detect API versions prior to 1.8. Earlier + * versions incorrectly used int4 for certain columns. This caused + * various problems. For example, an int4 version of the "oldest_xact" + * column would not work with TransactionId values that happened to exceed + * PG_INT32_MAX. + * + * There is no way to reliably avoid the problems created by the old + * function definition at this point, so insist that the user update the + * extension. + */ + if (tupleDesc->natts < BT_METAP_COLS_V1_8) + ereport(ERROR, + (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), + errmsg("function has wrong number of declared columns"), + errhint("To resolve the problem, update the \"pageinspect\" extension to the latest version."))); + j = 0; values[j++] = psprintf("%d", metad->btm_magic); values[j++] = psprintf("%d", metad->btm_version); - values[j++] = psprintf("%d", metad->btm_root); - values[j++] = psprintf("%d", metad->btm_level); - values[j++] = psprintf("%d", metad->btm_fastroot); - values[j++] = psprintf("%d", metad->btm_fastlevel); + values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_root); + values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_level); + values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_fastroot); + values[j++] = psprintf(INT64_FORMAT, (int64) metad->btm_fastlevel); /* * Get values of extended metadata if available, use default values diff --git a/contrib/pageinspect/pageinspect--1.7--1.8.sql b/contrib/pageinspect/pageinspect--1.7--1.8.sql index e34c214c93..45031a026a 100644 --- a/contrib/pageinspect/pageinspect--1.7--1.8.sql +++ b/contrib/pageinspect/pageinspect--1.7--1.8.sql @@ -22,12 +22,12 @@ DROP FUNCTION bt_metap(text); CREATE FUNCTION bt_metap(IN relname text, OUT magic int4, OUT version int4, - OUT root int4, - OUT level int4, - OUT fastroot int4, - OUT fastlevel int4, - OUT oldest_xact int4, - OUT last_cleanup_num_tuples real, + OUT root int8, + OUT level int8, + OUT fastroot int8, + OUT fastlevel int8, + OUT oldest_xact xid, + OUT last_cleanup_num_tuples float8, OUT allequalimage boolean) AS 'MODULE_PATHNAME', 'bt_metap' LANGUAGE C STRICT PARALLEL SAFE;