Analyser toutes les tables pour un schéma donné
CREATE OR REPLACE FUNCTION analyze_table(schema_name TEXT)
RETURNS VOID AS
$$
DECLARE
table_record RECORD;
BEGIN
FOR table_record IN
SELECT tablename
FROM pg_tables
WHERE schemaname = schema_name
LOOP
EXECUTE format('ANALYZE %I.%I', schema_name, table_record.tablename);
RAISE NOTICE 'Analyzed table %I.%I', schema_name, table_record.tablename;
END LOOP;
END;
$$
LANGUAGE plpgsql;
Laisser un commentaire