Home / Companies / Yugabyte / Blog / Post Details
Content Deep Dive

A SQL Stopwatch Utility for YugabyteDB or PostgreSQL as an Alternative for “\timing on”

Blog post from Yugabyte

Post Details
Company
Date Published
Author
Bryn Llewellyn
Word Count
3,749
Language
English
Hacker News Points
-
Summary

This blog post discusses implementing a timer for multi-statement operations in YugabyteDB or PostgreSQL, providing an alternative to the native "\timing on" feature. The author highlights the limitations of "\timing on", such as not supporting end-to-end timing and not storing results in a spool file. To address this, they propose using SQL to implement a stopwatch that reads the wall clock at the start and finish of operations, allowing for end-to-end timing and recording the measured time in a spool file. The author provides several schemes for implementing the memo, including using an ordinary table, a user-defined run-time parameter, a ysqlsh variable, or an ordinary PL/pgSQL variable within a procedure. They compare the noise levels of these approaches and recommend choosing the best method based on the specific use case. Ultimately, they suggest installing the procedure start_stopwatch() and function stopwatch_reading() centrally in any database to make ad hoc end-to-end timing easy for users.