diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index f56c70263e07b..559ec89c94bd2 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -3836,6 +3836,14 @@ SELECT 1 \bind \sendpipeline 1 second are also shown in minutes:seconds format, with hours and days fields added if needed. + + Note that query execution time is always measured regardless of the + \timing setting. The \timing command + only controls whether the timing information is displayed. The measured + time is always available in the LAST_QUERY_MS variable + (see ), which allows + scripts to access timing data programmatically without cluttering output. + @@ -4536,6 +4544,36 @@ bar + + LAST_QUERY_MS + + + The execution time of the most recent SQL statement, measured in + milliseconds and stored as a decimal number with three decimal places. + This variable is always updated after each query execution, regardless of + the \timing setting. The \timing + command only controls whether the timing is displayed; measurement + always occurs. + + + The variable is initialized to 0 at the start of each + psql session. This allows scripts to access + query timing programmatically for conditional logic or logging without + displaying timing information in the output. + + + Example: + +\timing off +SELECT expensive_operation(); +\if :LAST_QUERY_MS > 1000 + \echo 'WARNING: Query took more than 1 second' +\endif + + + + + ON_ERROR_ROLLBACK