Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to benchmark some SQL-queries agains my PostgreSQL database. Is there any way I can time SQL-queries using psql?

share|improve this question
For more details on benchmarking PostgreSQL queries: – Franck Dernoncourt May 15 '13 at 22:29
up vote 142 down vote accepted

Just turn on timing by entering:


share|improve this answer
From out bash, the "-c" option of psql does not allow this setting. You can do this with something like: psql --o /dev/null <<EOF \timing select 1 EOF – 3manuek Jul 14 at 17:38

Timing can be turned on with \timing at the psql prompt (as Caleb already said).

If you are on 8.4 or above, you can add an optional on/off argument to \timing, which can be helpful if you want to be able to set timing on in .psqlrc - you can then set \timing on explicitly in a script where plain \timing would otherwise toggle it off

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.