-- ---------------------------------------------------------------------- -- amcheck verify_heapam on a CFS heap, and SET TABLESPACE preserving the -- CFS policy. -- -- verify_heapam scans every heap page through the buffer manager (a -- BAS_BULKREAD strategy), so on a CFS heap it reads decompressed pages and -- validates tuple structure, visibility, and XID/MXFF states. A clean run -- is an oracle that decompressed CFS heap pages are correct. -- -- The matrix note for this case: SET TABLESPACE must preserve compression. -- Moving a CFS table to another tablespace rewrites it through the CFS smgr -- write path; the destination table must still be CFS, with sidecars, and -- verify_heapam-clean. -- -- Based on contrib/amcheck/sql/check_heap.sql. -- ---------------------------------------------------------------------- CREATE EXTENSION amcheck; CREATE EXTENSION pg_buffercache; CREATE FUNCTION cfs_evict(p_rel regclass) RETURNS void LANGUAGE plpgsql AS $$ BEGIN PERFORM pg_buffercache_evict_relation(p_rel); END $$; CREATE TABLE cfsheap (a integer, b text) WITH (algorithm = 'lz4'); INSERT INTO cfsheap (a, b) SELECT gs, repeat('x', gs) FROM generate_series(1, 50) gs; SELECT cfs_relation_policy('cfsheap') AS policy_before, cfs_relation_has_sidecars('cfsheap') AS sidecars_before; -- Evict so verify_heapam reads through CFS decompression. CHECKPOINT; SELECT cfs_evict('cfsheap'); -- verify_heapam must report no corruption on the CFS heap. SELECT count(*) AS corrupt FROM verify_heapam(relation := 'cfsheap', skip := 'none'); -- SET TABLESPACE rewrites the table; the destination must still be CFS. SET allow_in_place_tablespaces = true; CREATE TABLESPACE cfsheap_tblspc LOCATION ''; BEGIN; ALTER TABLE cfsheap SET TABLESPACE cfsheap_tblspc; COMMIT; SELECT cfs_relation_policy('cfsheap') AS policy_after_tsp, cfs_relation_has_sidecars('cfsheap') AS sidecars_after_tsp; CHECKPOINT; SELECT cfs_evict('cfsheap'); -- After the rewrite the moved table must still verify clean. SELECT count(*) AS corrupt_after_move FROM verify_heapam(relation := 'cfsheap', skip := 'none'); -- FREEZE changes the visibility/XID state that verify_heapam inspects; the -- frozen CFS pages must still be clean. VACUUM (FREEZE, DISABLE_PAGE_SKIPPING) cfsheap; SELECT count(*) AS corrupt_after_freeze FROM verify_heapam(relation := 'cfsheap', skip := 'none'); DROP TABLE cfsheap; DROP TABLESPACE cfsheap_tblspc; DROP EXTENSION pg_buffercache; DROP EXTENSION amcheck;