DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Statistics / Cumulative Query and Index Statistics

track_functions

Collects function-level statistics on database activity.

  • Default: none
  • Type: enum
  • Values: none · pl · all
  • Applies: Session (superuser)

In plain words

Lets you see how often each of your functions is called and how much time it takes, in pg_stat_user_functions. You choose: nothing (default), only procedural-language functions such as PL/pgSQL, or also SQL and C functions.

For DBAs and operators

Values: none (off), pl (PL/pgSQL, PL/Python, PL/Perl …), all (also LANGUAGE sql and C functions). Built-in internal functions are never tracked, and simple SQL functions that the planner inlines into the calling query are not tracked either, because they are never called as functions.

pg_stat_user_functions columns: calls, total_time (ms, including functions it calls) and self_time (ms, excluding them). self_time is the one to sort by when hunting for the expensive function in a nest of calls:

SELECT schemaname, funcname, calls,
       round(total_time) AS total_ms, round(self_time) AS self_ms,
       round(self_time / calls, 3) AS ms_per_call
  FROM pg_stat_user_functions ORDER BY self_time DESC LIMIT 10;

Overhead is a clock read per call; for tiny functions called millions of times, all can be measurable. pl is a sensible permanent setting for applications with business logic in PL/pgSQL. Counters are reset with pg_stat_reset() or pg_stat_reset_single_function_counters(oid).

How to change it

A superuser (or a role granted SET) can change it per session with SET.

See it in context

Cumulative statistics

Related parameters

track_counts track_activities compute_query_id

All Statistics parameters