Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get timing from the PgSQL DB

I'm attempting to get the timing of a query using the pg gem. I saw the documentation, but I did not find anything. I want to know if there is something like query.time.

I added \timing to ~/.psqlrc, so the command is active by default. If I write the query in the Postgres console the time is active.

This is the code:

conn = PGconn.open(:dbname => 'my_db') 
query=conn.exec('SELECT * from some_table')
puts query.num_tuples -> this work
puts query.time  -> undefined method

I need to measure the time of Postgres itself, I cannot use the Time class from Ruby.

like image 928
Enzo Zerega Avatar asked Mar 24 '26 22:03

Enzo Zerega


1 Answers

Try this as it should return the time back.

puts conn.exec("EXPLAIN ANALYZE SELECT * FROM some_table").values

like image 159
Nabeel Avatar answered Mar 27 '26 13:03

Nabeel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!