What is a good way to track the timings of queries in postgresql without looking in the log file? -
i've got function in postgres database lot of analysis; consists of succession of update , insert statements , throws output. i'd figure out statements execute slowly, without looking through log files. (i'm more comfortable sql with, say, perl, write date / time arithmetic queries in order spot problems.)
i have table, activity_log:
create table activity_log ( action character varying(250), action_date date, action_tune time without time zone );
then throughout function, after each insert / update write statements like
insert activity_log (action_date, action_tune, action) values (current_date, current_timestamp, 'insert base_model');
so function looks this:
create function rebucket(pos_control character varying, absolute_max_cpc numeric, absolute_max_bucket character varying) returns integer $body$ declare qty int; begin insert activity_log (action_date, action_tune, action) values (current_date, current_timestamp, 'off go'); -- takes 5 minutes insert activity_log (action_date, action_tune, action) values (current_date, current_timestamp, 'insert base_model'); -- else takes 5 minutes ... insert activity_log (action_date, action_tune, action) values (current_date, current_timestamp, 'insert diagnostics'); end $body$ language plpgsql volatile
i've got away in other databases in past, when try approach in postgres (9.1 on windows 7), whenever run whole function date , time in activity_log same every statement within function: in example above,
select * activity_log
gets me
off go 2013-05-13 12:33:23:386 insert base_model 2013-05-13 12:33:23:386 insert diagnostics 2013-05-13 12:33:23:386
(the function takes 5 minutes hour run, depending on parameters feed it, , has upwards of 20 different statements within there, seems highly unlikely every statement completed within same 1/100th of second.)
why that?
the timestamp using gives start of current transaction. if in manuals see want clock_timestamp()
.
Comments
Post a Comment