\timing
This meta-command reports, in milliseconds, the length of time each SQL statement runs. The results include:
- the length of time required to fetch the first block of rows
- the total time until the last block is formatted
For example:
=> SELECT * from allsales; state | name | sales --------------------- NY | B | 20 NY | C | 15 MA | A | 40 (3 rows) Time: First fetch (7 rows): 59.264 ms. All rows formatted: 59.362 ms
Timing is off by default. To determine the state of the timing function, enter the following:
=> \timing Timing is on
This example indicates that timing is off.
Toggle \timing function
You can set the timing state by entering on or off:
=> \timing on Timing is on
=> \timing off Timing is off
Alternatively, enter the function name without an argument to automatically toggle the state, whether it's on or off. For example, if you run \timing on, running \timing disables timing:
=> \timing on Timing is on => \timing Timing is off
Enable \timing from the vsql Command Line
You can enable \timing from the command line using the vsql -i command. You can only use -i with the -c (command) and -f (filename) commands. For more information see Command-Line Options.
From the command line enter the -i option before running a session to turn timing on. For example:
$VSQL -h host1 -U user1 -d VMart -p 15 -w ****** -i -f transactions.sql
$VSQL-h host1 -U user1 -d VMart -p 15 -w ****** -i -c "SELECT user_name, ssl_state, authentication_method, client_authentication_name, client_type FROM sessions WHERE session_id=(SELECT session_id FROM current_session);"
Example
The following example shows a SQL command with timing on:
=> \SELECT user_name, ssl_state, authentication_method, client_authentication_name, client_type FROM sessions WHERE session_id=(SELECT session_id FROM current_session); user_name | ssl_state | authentication_method | client_authentication_name | client_type ------------------------------------------------------------------------------------------------- dbadmin | None | ImpTrust | default; Implicit Trust | vsql (1 row) Time: First fetch (1 row): 44.388 ms. All rows formatted: 40.502 ms
The following table provides a quick guide on what occurs when you run \timing commands starting with the \timing being on:
| vsql command | Starting \timing state = on |
|---|---|
=> \timing on |
Keeps timing on |
=> \timing |
Turns timing off |
=> \timing off |
Turns timing off |
| => \timing on | Turns timing on |