F.70. pg_wait_profile — sample-based profiling of database activity#
F.70. pg_wait_profile — sample-based profiling of database activity #
Version: 1.0
F.70.1. Overview #
Tantor SE reports the current wait event for each backend.
However, gathering descriptive statistical profile about server
behavior requires repeated sampling of wait events.
pg_wait_profile provides functions to sample
database activity externally from client backends.
Caution
Extension just tracks backend processes having connection to any database. It ignores background workers performing some external to database tasks like log collector.
F.70.2. Usage #
F.70.2.1. Installation #
CREATE EXTENSION pg_wait_profile;
No need to setup extension to
shared_preload_libraries
F.70.2.2. Functions #
-
wait_profile_session( pid#int4, durationintervalDEFAULT'10 seconds', sample_periodintervalDEFAULT'10 milliseconds', with_pidsbooleanDEFAULTfalse) Samples processes that constitute a client session, including the main backend process and its related parallel workers, over the specified
durationwith the givensample_period.-
wait_profile_procs( pids#int4[], durationintervalDEFAULT'10 seconds', sample_periodintervalDEFAULT'10 milliseconds', with_pidsbooleanDEFAULTfalse) Samples all currently alive backend processes specified in the
pidsarray over the specifieddurationwith the givensample_period.If
pidsisNULL, samples all backend processes in the current database.-
wait_profile_all( duration#intervalDEFAULT'10 seconds', sample_periodintervalDEFAULT'10 milliseconds', with_pidsbooleanDEFAULTfalse) Samples all backend processes in the current database over the specified
durationwith the givensample_period.This function is equivalent to calling
wait_profile_procs(NULL, ...).
All three functions output the following table structure:
| Column | Type | Description | Details |
|---|---|---|---|
pid
|
int4
| Process ID |
NULL when incoming options
with_pids is false
|
backend_type
|
text
| Type of backend |
Possible values are identical to ones in the same column
name in pg_stat_activity view
|
database_id
|
int4
| Database ID | |
user_id
|
int4
| User ID | |
state
|
text
| Backend state |
Possible values are identical to ones in the same column
name in pg_stat_activity view
|
query_id
|
int8
| Query identifier |
NULL means the state out of query
execution or
fast path
function calling or disabled query id
computing on backend’s side
|
plan_id
|
int8
| Plan identifier |
Currently disabled and always NULL
|
event_type
|
text
| Wait event type |
CPU time means the "out of waiting" state,
or an uncovered Tantor SE (unknown) wait.
|
event
|
text
| Wait event name | |
count
|
int8
| Number of samples |
Note
To enable query_id computation there are
two ways:
set up explicitly
compute_query_idtoon(on specific backend or on a whole postgres cluster viaALTER SYSTEM SET)set up
compute_query_idtoauto(default value) orregressand extendshared_preload_librariesorsession_preload_librariesto contain thepg_wait_profileextension
Caution
NULL value of query id
has two meanings: out of query execution and disabled query id
computing on backend’s side. As the second option might be
turned off explicitly on session side, counting statistics for
out of query execution will collapse with overall subsequent
one after turning off of query id computing.