May 2018
Intermediate to advanced
576 pages
30h 25m
English
PostgreSQL provides a version of the pg_stat_activity view capable of capturing many kinds of waits; however, in older versions pg_stat_activity could only detect waits on locks such as those placed on SQL objects, via the pg_stat_activity.waiting field.
Although this is the main cause of waiting when using pure SQL, it is possible to write a query in any of PostgreSQL's embedded languages that can wait on other system resources, such as waiting for an HTTP response, for a file write to get completed, or just waiting on a timer.
As an example, you can make your backend sleep for a certain number of seconds using pg_sleep(seconds). While you are monitoring pg_stat_activity, open a new terminal session ...