How Do I Evaluate Whether the Current Table or Database Requires VACUUM?
GaussDB provides the system function pg_autovac_status to query whether a table has reached the VACUUM threshold. Combined with the pg_class system catalog, you can query the top N tables with the highest dead row rates. For example, the following SQL statement queries the top 10 tables with the highest dead row rates:
SELECT C.oid AS relid, N.nspname AS schemaname, C.relname AS relname, C.reltuples AS n_rel_tup, pg_catalog.pg_stat_get_dead_tuples(C.oid) AS n_dead_tup, pg_catalog.pg_autovac_status(C.oid).doVacuum as need_Vacuum, CAST(n_dead_tup / C.reltuples AS decimal(10, 2)) AS dead_radio FROM pg_class C LEFT JOIN pg_index I ON C.oid = I.indrelid LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) WHERE C.relkind IN ('r') and C.reltuples > 0 GROUP BY C.oid, N.nspname, C.relname, C.reltuples, need_Vacuum order by dead_radio desc limit 10;
The command output is as follows:
relid | schemaname | relname | n_rel_tup | n_dead_tup | need_vacuum | dead_radio -------+------------+-------------------------+-----------+------------+-------------+------------ 2604 | pg_catalog | pg_attrdef | 1 | 14 | | 14.00 2606 | pg_catalog | pg_constraint | 12 | 15 | | 1.25 3118 | pg_catalog | pg_foreign_table | 2 | 2 | | 1.00 3079 | pg_catalog | pg_extension | 24 | 15 | | .63 2601 | pg_catalog | pg_am | 11 | 4 | | .36 1417 | pg_catalog | pg_foreign_server | 4 | 1 | | .25 2610 | pg_catalog | pg_index | 421 | 82 | | .19 2328 | pg_catalog | pg_foreign_data_wrapper | 6 | 1 | | .17 2619 | pg_catalog | pg_statistic | 1231 | 187 | | .15 2609 | pg_catalog | pg_description | 4748 | 25 | | .01 (10 rows)
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot