RESET vacuum_freeze_min_age;
DROP TABLE IF EXISTS vacfailure;
CREATE TABLE vacfailure(id serial primary key, data int);
-- disable autovac so we don't have spurious failures
ALTER TABLE vacfailure SET (AUTOVACUUM_ENABLED = false);

-- insert data and mark as all-visible
INSERT INTO vacfailure(data) SELECT * FROM generate_series(1, 100000);
SELECT relname, relfrozenxid, txid_current() FROM pg_class WHERE oid = 'vacfailure'::regclass;
SELECT min(xmin::text::bigint) FROM vacfailure WHERE NOT xmin = 2;
VACUUM VERBOSE vacfailure;
SELECT min(xmin::text::bigint) FROM vacfailure WHERE NOT xmin = 2;

-- so the test doesn't need to create a couple million xids
SET vacuum_freeze_min_age = 0;
SELECT txid_current();SELECT txid_current();SELECT txid_current();
SELECT txid_current();SELECT txid_current();SELECT txid_current();
SELECT txid_current();SELECT txid_current();SELECT txid_current();

SELECT relname, relfrozenxid, txid_current() FROM pg_class WHERE oid = 'vacfailure'::regclass;
-- produce dead rows at the end of the relation
BEGIN;
INSERT INTO vacfailure(data) SELECT * FROM generate_series(1, 500000);
ROLLBACK;
-- partial vacuum, if "row versions in 2213 out of 2655 pages" or similar
VACUUM VERBOSE vacfailure;
-- if different than the the last time, the bug has hit
SELECT relname, relfrozenxid, txid_current() FROM pg_class WHERE oid = 'vacfailure'::regclass;
SELECT min(xmin::text::bigint) FROM vacfailure WHERE NOT xmin = 2;
