PL/pgSQL benchmarking
PostgreSQL 8.4 added a feature to allow track statistics on how long each database function written in PL/pgSQL and similar languages take to execute. To enable this edit your postgresql conf
:
track_functions = all
The other options here is pl
, which only tracks the pl/* language functions instead of all of them (that is, not the ones written in C). Once that's done, you've executed some functions, and you've waited a moment for those to show up in the statistics collector, the following query will show you what executed:
SELECT * FROM pg_stat_user_functions;
In earlier versions, it was possible to build your own test harness using the technique described at http://www.justatheory.com/computers/databases/postgresql/benchmarking_function.html.
If instead you'd like to figure out which individual statements are responsible for the overhead, instead of just finding out how long the entire function takes, you'll need something more like...