mirror of https://github.com/postgres/postgres
Improve the regression tests of VACUUM (PROCESS_TOAST)
All the regression tests of VACUUM (PROCESS_TOAST) were only checking if the commands were able to run, without checking if VACUUM was really running on what it should. This expands this set of tests so as we now look at pg_stat_all_tables.vacuum_count to see how many vacuums have been run on a given table and its toast relation. Extracted from a larger patch by the same author, as this is useful on its own. Special thanks to Álvaro Herrera for the idea of using pg_stat_all_tables to check the state of the toast relation. Author: Nathan Bossart Reviewed-by: Masahiko Sawada Discussion: https://postgr.es/m/20221230000028.GA435655@nathanxps13
This commit is contained in:
parent
9effa55236
commit
46d490ac19
|
@ -277,10 +277,36 @@ BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
|
|||
ANALYZE vactst;
|
||||
COMMIT;
|
||||
-- PROCESS_TOAST option
|
||||
ALTER TABLE vactst ADD COLUMN t TEXT;
|
||||
ALTER TABLE vactst ALTER COLUMN t SET STORAGE EXTERNAL;
|
||||
VACUUM (PROCESS_TOAST FALSE) vactst;
|
||||
VACUUM (PROCESS_TOAST FALSE, FULL) vactst;
|
||||
CREATE TABLE vac_option_tab (a INT, t TEXT);
|
||||
INSERT INTO vac_option_tab SELECT a, 't' || a FROM generate_series(1, 10) AS a;
|
||||
ALTER TABLE vac_option_tab ALTER COLUMN t SET STORAGE EXTERNAL;
|
||||
-- Check the number of vacuums done on table vac_option_tab and on its
|
||||
-- toast relation, to check that PROCESS_TOAST works on what it should.
|
||||
CREATE VIEW vac_option_tab_counts AS
|
||||
SELECT CASE WHEN c.relname IS NULL
|
||||
THEN 'main' ELSE 'toast' END as rel,
|
||||
s.vacuum_count
|
||||
FROM pg_stat_all_tables s
|
||||
LEFT JOIN pg_class c ON s.relid = c.reltoastrelid
|
||||
WHERE c.relname = 'vac_option_tab' OR s.relname = 'vac_option_tab'
|
||||
ORDER BY rel;
|
||||
VACUUM (PROCESS_TOAST TRUE) vac_option_tab;
|
||||
SELECT * FROM vac_option_tab_counts;
|
||||
rel | vacuum_count
|
||||
-------+--------------
|
||||
main | 1
|
||||
toast | 1
|
||||
(2 rows)
|
||||
|
||||
VACUUM (PROCESS_TOAST FALSE) vac_option_tab;
|
||||
SELECT * FROM vac_option_tab_counts;
|
||||
rel | vacuum_count
|
||||
-------+--------------
|
||||
main | 2
|
||||
toast | 1
|
||||
(2 rows)
|
||||
|
||||
VACUUM (PROCESS_TOAST FALSE, FULL) vac_option_tab; -- error
|
||||
ERROR: PROCESS_TOAST required with VACUUM FULL
|
||||
-- SKIP_DATABASE_STATS option
|
||||
VACUUM (SKIP_DATABASE_STATS) vactst;
|
||||
|
@ -288,6 +314,8 @@ VACUUM (SKIP_DATABASE_STATS) vactst;
|
|||
VACUUM (ONLY_DATABASE_STATS);
|
||||
VACUUM (ONLY_DATABASE_STATS) vactst; -- error
|
||||
ERROR: ONLY_DATABASE_STATS cannot be specified with a list of tables
|
||||
DROP VIEW vac_option_tab_counts;
|
||||
DROP TABLE vac_option_tab;
|
||||
DROP TABLE vaccluster;
|
||||
DROP TABLE vactst;
|
||||
DROP TABLE vacparted;
|
||||
|
|
|
@ -232,10 +232,24 @@ ANALYZE vactst;
|
|||
COMMIT;
|
||||
|
||||
-- PROCESS_TOAST option
|
||||
ALTER TABLE vactst ADD COLUMN t TEXT;
|
||||
ALTER TABLE vactst ALTER COLUMN t SET STORAGE EXTERNAL;
|
||||
VACUUM (PROCESS_TOAST FALSE) vactst;
|
||||
VACUUM (PROCESS_TOAST FALSE, FULL) vactst;
|
||||
CREATE TABLE vac_option_tab (a INT, t TEXT);
|
||||
INSERT INTO vac_option_tab SELECT a, 't' || a FROM generate_series(1, 10) AS a;
|
||||
ALTER TABLE vac_option_tab ALTER COLUMN t SET STORAGE EXTERNAL;
|
||||
-- Check the number of vacuums done on table vac_option_tab and on its
|
||||
-- toast relation, to check that PROCESS_TOAST works on what it should.
|
||||
CREATE VIEW vac_option_tab_counts AS
|
||||
SELECT CASE WHEN c.relname IS NULL
|
||||
THEN 'main' ELSE 'toast' END as rel,
|
||||
s.vacuum_count
|
||||
FROM pg_stat_all_tables s
|
||||
LEFT JOIN pg_class c ON s.relid = c.reltoastrelid
|
||||
WHERE c.relname = 'vac_option_tab' OR s.relname = 'vac_option_tab'
|
||||
ORDER BY rel;
|
||||
VACUUM (PROCESS_TOAST TRUE) vac_option_tab;
|
||||
SELECT * FROM vac_option_tab_counts;
|
||||
VACUUM (PROCESS_TOAST FALSE) vac_option_tab;
|
||||
SELECT * FROM vac_option_tab_counts;
|
||||
VACUUM (PROCESS_TOAST FALSE, FULL) vac_option_tab; -- error
|
||||
|
||||
-- SKIP_DATABASE_STATS option
|
||||
VACUUM (SKIP_DATABASE_STATS) vactst;
|
||||
|
@ -244,6 +258,8 @@ VACUUM (SKIP_DATABASE_STATS) vactst;
|
|||
VACUUM (ONLY_DATABASE_STATS);
|
||||
VACUUM (ONLY_DATABASE_STATS) vactst; -- error
|
||||
|
||||
DROP VIEW vac_option_tab_counts;
|
||||
DROP TABLE vac_option_tab;
|
||||
DROP TABLE vaccluster;
|
||||
DROP TABLE vactst;
|
||||
DROP TABLE vacparted;
|
||||
|
|
Loading…
Reference in New Issue