Skip to content

Commit

Permalink
Remove pg_advance_vacuum_cleanup_age() support in PostgreSQL 16 and l…
Browse files Browse the repository at this point in the history
…ater.

pg_advance_vacuum_cleanup_age() relies on vacuum_defer_cleanup_age GUC,
which was removed in PostgreSQL 16, making the function unavailable
in PostgreSQL 16 and later releases. As a result, compiling pg_cheat_funcs
on PostgreSQL 16 resulted in errors.

To resolve this issue, this commit drops support for
pg_advance_vacuum_cleanup_age() in PostgreSQL 16 and later.
The function is now only defined and created for PostgreSQL 15 or earlier
releases, ensuring that pg_cheat_funcs can be compiled without issues
on those versions.
  • Loading branch information
MasaoFujii committed Apr 26, 2023
1 parent cb428ad commit 0328555
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 34 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ REGRESS += $(shell if [ $(MAJORVERSION_INT) -ge 95 ]; then echo pglz_compress; f
REGRESS += $(shell if [ $(MAJORVERSION_INT) -ge 94 ]; then echo pg_chr pg_94_or_later; else echo pg_chr_91_93; fi)
REGRESS += $(shell if [ $(MAJORVERSION_INT) -ge 92 ]; then echo pg_cached_plan; fi)
REGRESS += $(shell if [ $(MAJORVERSION_INT) -ge 130 ]; then echo pg_xid_to_xid8; fi)
REGRESS += $(shell if [ $(MAJORVERSION_INT) -lt 160 ]; then echo pg_advance_vacuum_cleanup_age; fi)

PGFILEDESC = "pg_cheat_funcs - provides cheat (but useful) functions"

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ This function must not be used for a purpose other than debug.
This function is restricted to superusers by default,
but other users can be granted EXECUTE to run the function.

This function is available only in PostgreSQL 15 or earlier,
as the vacuum_defer_cleanup_age that it depends on was removed in 16.

### void pg_checkpoint(fast bool, wait bool, force bool)
Perform a checkpoint.
If fast is true (default), a checkpoint will finish as soon as possible.
Expand Down
17 changes: 17 additions & 0 deletions expected/pg_advance_vacuum_cleanup_age.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE EXTENSION pg_cheat_funcs;
\pset null '(null)'
DO $$
DECLARE
orig_cleanup_age text := current_setting('vacuum_defer_cleanup_age');
BEGIN
PERFORM pg_advance_vacuum_cleanup_age(99);
IF current_setting('vacuum_defer_cleanup_age') <> '-99' THEN
RAISE WARNING 'could not advance vacuum cleanup age properly.';
END IF;
PERFORM pg_advance_vacuum_cleanup_age();
IF current_setting('vacuum_defer_cleanup_age') <> orig_cleanup_age THEN
RAISE NOTICE 'could not reset vacuum cleanup age properly.';
END IF;
END;
$$ LANGUAGE plpgsql;
DROP EXTENSION pg_cheat_funcs;
14 changes: 0 additions & 14 deletions expected/pg_cheat_funcs.out
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,6 @@ SELECT pg_set_next_xid(next_xid) = next_xid FROM pg_xid_assignment();
t
(1 row)

DO $$
DECLARE
orig_cleanup_age text := current_setting('vacuum_defer_cleanup_age');
BEGIN
PERFORM pg_advance_vacuum_cleanup_age(99);
IF current_setting('vacuum_defer_cleanup_age') <> '-99' THEN
RAISE WARNING 'could not advance vacuum cleanup age properly.';
END IF;
PERFORM pg_advance_vacuum_cleanup_age();
IF current_setting('vacuum_defer_cleanup_age') <> orig_cleanup_age THEN
RAISE NOTICE 'could not reset vacuum cleanup age properly.';
END IF;
END;
$$ LANGUAGE plpgsql;
SELECT to_octal(num) FROM generate_series(1, 10) num;
to_octal
----------
Expand Down
22 changes: 17 additions & 5 deletions pg_cheat_funcs--1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,23 @@ AS 'MODULE_PATHNAME'
LANGUAGE C STRICT VOLATILE;
REVOKE ALL ON FUNCTION pg_oid_assignment() FROM PUBLIC;

CREATE FUNCTION pg_advance_vacuum_cleanup_age(integer DEFAULT NULL)
RETURNS integer
AS 'MODULE_PATHNAME'
LANGUAGE C CALLED ON NULL INPUT VOLATILE;
REVOKE ALL ON FUNCTION pg_advance_vacuum_cleanup_age(integer) FROM PUBLIC;
-- Create pg_advance_vacuum_cleanup_age() only in 15 or earlier,
-- as the vacuum_defer_cleanup_age GUC that it depends on was
-- removed in 16.
DO $$
DECLARE
pgversion INTEGER;
BEGIN
SELECT current_setting('server_version_num')::INTEGER INTO pgversion;
IF pgversion < 160000 THEN
CREATE FUNCTION pg_advance_vacuum_cleanup_age(integer DEFAULT NULL)
RETURNS integer
AS 'MODULE_PATHNAME'
LANGUAGE C CALLED ON NULL INPUT VOLATILE;
REVOKE ALL ON FUNCTION pg_advance_vacuum_cleanup_age(integer) FROM PUBLIC;
END IF;
END;
$$;

CREATE FUNCTION pg_checkpoint(bool DEFAULT true, bool DEFAULT true,
bool DEFAULT true)
Expand Down
6 changes: 6 additions & 0 deletions pg_cheat_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ PG_FUNCTION_INFO_V1(pg_xid_to_xid8);
#endif
PG_FUNCTION_INFO_V1(pg_set_next_oid);
PG_FUNCTION_INFO_V1(pg_oid_assignment);
#if PG_VERSION_NUM < 160000
PG_FUNCTION_INFO_V1(pg_advance_vacuum_cleanup_age);
#endif
PG_FUNCTION_INFO_V1(pg_checkpoint);
#if PG_VERSION_NUM < 120000
PG_FUNCTION_INFO_V1(pg_promote);
Expand Down Expand Up @@ -202,7 +204,9 @@ Datum pg_set_next_xid(PG_FUNCTION_ARGS);
Datum pg_xid_assignment(PG_FUNCTION_ARGS);
Datum pg_set_next_oid(PG_FUNCTION_ARGS);
Datum pg_oid_assignment(PG_FUNCTION_ARGS);
#if PG_VERSION_NUM < 160000
Datum pg_advance_vacuum_cleanup_age(PG_FUNCTION_ARGS);
#endif
Datum pg_checkpoint(PG_FUNCTION_ARGS);
#if PG_VERSION_NUM < 120000
Datum pg_promote(PG_FUNCTION_ARGS);
Expand Down Expand Up @@ -1347,6 +1351,7 @@ pg_oid_assignment(PG_FUNCTION_ARGS)
heap_form_tuple(tupdesc, values, nulls)));
}

#if PG_VERSION_NUM < 160000
/*
* Specify the number of transactions by which VACUUM and HOT updates
* will advance cleanup of dead row versions.
Expand Down Expand Up @@ -1375,6 +1380,7 @@ pg_advance_vacuum_cleanup_age(PG_FUNCTION_ARGS)

PG_RETURN_INT32(-vacuum_defer_cleanup_age);
}
#endif /* PG_VERSION_NUM < 160000 */

/*
* Perform a checkpoint.
Expand Down
20 changes: 20 additions & 0 deletions sql/pg_advance_vacuum_cleanup_age.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CREATE EXTENSION pg_cheat_funcs;

\pset null '(null)'

DO $$
DECLARE
orig_cleanup_age text := current_setting('vacuum_defer_cleanup_age');
BEGIN
PERFORM pg_advance_vacuum_cleanup_age(99);
IF current_setting('vacuum_defer_cleanup_age') <> '-99' THEN
RAISE WARNING 'could not advance vacuum cleanup age properly.';
END IF;
PERFORM pg_advance_vacuum_cleanup_age();
IF current_setting('vacuum_defer_cleanup_age') <> orig_cleanup_age THEN
RAISE NOTICE 'could not reset vacuum cleanup age properly.';
END IF;
END;
$$ LANGUAGE plpgsql;

DROP EXTENSION pg_cheat_funcs;
15 changes: 0 additions & 15 deletions sql/pg_cheat_funcs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,6 @@ SELECT pg_eucjp('xa4', 'xa2');

SELECT pg_set_next_xid(next_xid) = next_xid FROM pg_xid_assignment();

DO $$
DECLARE
orig_cleanup_age text := current_setting('vacuum_defer_cleanup_age');
BEGIN
PERFORM pg_advance_vacuum_cleanup_age(99);
IF current_setting('vacuum_defer_cleanup_age') <> '-99' THEN
RAISE WARNING 'could not advance vacuum cleanup age properly.';
END IF;
PERFORM pg_advance_vacuum_cleanup_age();
IF current_setting('vacuum_defer_cleanup_age') <> orig_cleanup_age THEN
RAISE NOTICE 'could not reset vacuum cleanup age properly.';
END IF;
END;
$$ LANGUAGE plpgsql;

SELECT to_octal(num) FROM generate_series(1, 10) num;
SELECT to_octal(2147483647::integer);
SELECT to_octal(9223372036854775807::bigint);
Expand Down

0 comments on commit 0328555

Please sign in to comment.