Search code examples
postgresqlpsqltiming

How to use \timing in postgres


I want to know the time that it takes to execute a query in Postgres. I see a lot of answers that suggest to use \timing, but I'm newbie in Postgres and I don't know how to use it.


Solution

  • You can use \timing only with the command line client psql, since this is a psql command.

    It is a switch that turns execution time reporting on and off:

    test=> \timing
    Timing is on.
    test=> SELECT 42;
    ┌──────────┐
    │ ?column? │
    ├──────────┤
    │       42 │
    └──────────┘
    (1 row)
    
    Time: 0.745 ms
    test=> \timing
    Timing is off.