cinfis
cinfis

Reputation: 345

how to get time difference in microseconds to measure total query-time in postgresql?

I want to get process time of a query in microseconds.

I get always 0 result when i calculate the difference of two time(at the beginning and end of query) with CURRENT_TIMESTAMP() function.

Upvotes: 1

Views: 189

Answers (1)

Jay Kominek
Jay Kominek

Reputation: 8783

See section 9.9.4 of the documentation. The issue is (probably, given that you provide few details) that current_timestamp returns the time at the start of the transaction.

If you use clock_timestamp, you'll get different values within the transaction.

(If you want to time a lot of queries, you might be better off adjusting the logging of the server, if you have permission to do so. But for a one-off, this is probably ok.)

Upvotes: 1

Related Questions