Performance Profiling PL/pgSQL — auto_explain, pg_stat_user_functions, and Optimisation
Performance Profiling PL/pgSQL — auto_explain, pg_stat_user_functions, and Optimisation
A PL/pgSQL function that runs slowly is harder to diagnose than a slow SQL query because the slow SQL might be hidden inside a loop or conditional branch. PostgreSQL provides several tools to profile functions: pg_stat_user_functions, auto_explain, and manual instrumentation with RAISE and clock_timestamp().