Monday, January 10, 2011

Tip for testing database function performance

Suppose you've got a database function that's slow. You want to determine where the bottlenecks are, so you decide to pepper your function with RAISE NOTICE statements to output the current time at different points within the function. You try "RAISE NOTICE current_timestamp" and note that every time this statement is executed, the same timestamp is output. It's as if current_timestamp has been pre-set to be the moment in time when the function began executing. What to do? The solution is to use "RAISE NOTICE timeofday()" - this will reflect the actual time, not the time the function began executing.

(Please note that this applies to Postgres. I don't know if this post translates precisely for other DBMS's.)

Postgres performance considerations

A great article about Postgres performance considerations that the guys from thoughtbot have been so kind to share - read and enjoy!