Waiting for 8.4 – timing on/off

Yes, finally! David Fetter wrote, and Heikki Linnakangas committed patch which adds on/off arguments to \timing:

Before you could simply do:

\timing

to switch timing information:

# SELECT 1;
 ?COLUMN?
----------
        1
(1 ROW)
# \timing
Timing IS ON.
# SELECT 1;
 ?COLUMN?
----------
        1
(1 ROW)
TIME: 0.364 ms
# \timing
Timing IS off.
# SELECT 1;
 ?COLUMN?
----------
        1
(1 ROW)
#

The problem with this approach is that if you use .psqlrc to set your preferred psql environment, you might happen to put “\timing" there.

It means – that from start, all queries show they timing information.

And now, let's consider a simple case, when I have a simple .sql file, which contains some selects, but I wanted psql to print timings every time I ran it.

So, I wrote the file as:

\timing
SELECT 1;
SELECT 2;
\timing

Usually it would output:

=> psql -f z.sql
Timing is on.
 ?column?
----------
        1
(1 row)
Time: 0.795 ms
 ?column?
----------
        2
(1 row)
Time: 0.342 ms
Timing is off.

Which is pretty cool.

But if you did turn on timing in your .psqlrc, output will be different:

=> psql -f z.sql
Timing is off.
 ?column?
----------
        1
(1 row)
 ?column?
----------
        2
(1 row)
Timing is on.

Effectively I was “punished" by being user which cares about making my work environment most productive.

Luckily, David's patch, changes this. Now I can simply change the sql file to:

\timing ON
SELECT 1;
SELECT 2;
\timing off

And get desired results even if my .psqlrc tells psql to initially turn timings on. Great. Thanks David.

7 thoughts on “Waiting for 8.4 – timing on/off”

  1. How many of those interesting not-so-complex patches will be backported to 8.3?

  2. @Vincenzo Romano:
    according to my knowledge – 0.

    8.3 line is “closed” in terms of features. Only bugfixes are allowed.

  3. But if i have /timing turnned on in .psqlrc file and i run your four lines from the last example timings are now turrned off — and it’s not what I want.

    What about something that turns it on (regardless if it’s on or off) just for the next query? Something like

    > \timing single
    Timing is on.
    > SELECT …
    Timing is back to whatever it was before.

    I don’t realy like the “single” keyword but anyone with a better suggestion is welcome.

  4. Denis, the patch lets you set \timing to your desired setting unconditionally, which is what you want, if I’ve understood correctly.

  5. Nope, I want it to turn of the timing for next statement and don’t set it off (or leave it on) on the end of the script.

    Maybe it would be a better idea if you get a fresh “session” (all settings read from your config files are made default for your session) each time you enter the psql and you create another (sub)session each time you run something with \i. On the end of this (sub)session every changed setting would be restored to the default state/value of the “parent” session.

    This could be a solution that wouldn’t break my config even if the .sql file i run change the env completely.

  6. good goodthis post deserves nothing 🙁 hahaha just joking 😛 nice post 😛

Comments are closed.