Question

I am looking for a way to efficiently gather statistics that would tell me how many times each function gets called in a given period of time.

By efficient, I mean the stat collector should use as few disk I/O operations as possible.

It would be nice if I can also track some more stats like the return time however this is not necessary.

Was it helpful?

Solution

It's already built-in.

Check out the system view pg_stat_user_functions
http://www.postgresql.org/docs/current/static/monitoring-stats.html#PG-STAT-USER-FUNCTIONS-VIEW

Note that you need to enable that in your postgresql.conf:
http://www.postgresql.org/docs/current/static/monitoring-stats.html#MONITORING-STATS-SETUP

To reset the collected statistics, use pg_stat_reset():
http://www.postgresql.org/docs/current/static/monitoring-stats.html#MONITORING-STATS-FUNCTIONS

OTHER TIPS

In addition to the features horse mentioned, there's also:

I consider both pgbadger and pg_stat_statements essential components of any production PostgreSQL install.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top