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.
-
2here's the manual.Craig Ringer– Craig Ringer2016-11-15 05:11:50 +00:00Commented Nov 15, 2016 at 5:11
Add a comment
|
1 Answer
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.
13 Comments
aName
ok then if I want to test a select query how i can do that I tried to do what you have done, but instead of
select 42I do select * from my_db and I get Commande \select invalide.Laurenz Albe
Try
SELECT instead of \select, without the backslash.Laurenz Albe
If you want to measure the time it takes to output the result to a file, you can use
time on UNIX like this: time psql -P pager=off -c 'SELECT ...' >outfileLaurenz Albe
That makes things harder. You can execute a batch file with the
psql command line sandwiched between two echo %TIME%. Then a simple subtraction will tell how long it took.Bal Krishna Jha
@TimurShtatland thanks a lot. But I switched to
pgcli long back, which already provides timing along with many other features. |