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;
PostgreSQL Defrag les plus gros indexes et tables
[Postgres] Compter les lignes de plusieurs tables

Leave a Comment

Your email address will not be published. Required fields are marked *