lib/pghero/methods/query_stats.rb in pghero-2.5.1 vs lib/pghero/methods/query_stats.rb in pghero-2.6.0
- old
+ new
@@ -164,25 +164,27 @@
# http://www.craigkerstiens.com/2013/01/10/more-on-postgres-performance/
def current_query_stats(limit: nil, sort: nil, database: nil, query_hash: nil)
if query_stats_enabled?
limit ||= 100
sort ||= "total_minutes"
+ total_time = server_version_num >= 130000 ? "(total_plan_time + total_exec_time)" : "total_time"
query = <<-SQL
WITH query_stats AS (
SELECT
LEFT(query, 10000) AS query,
#{supports_query_hash? ? "queryid" : "md5(query)"} AS query_hash,
rolname AS user,
- (total_time / 1000 / 60) AS total_minutes,
- (total_time / calls) AS average_time,
+ (#{total_time} / 1000 / 60) AS total_minutes,
+ (#{total_time} / calls) AS average_time,
calls
FROM
pg_stat_statements
INNER JOIN
pg_database ON pg_database.oid = pg_stat_statements.dbid
INNER JOIN
pg_roles ON pg_roles.oid = pg_stat_statements.userid
WHERE
+ calls > 0 AND
pg_database.datname = #{database ? quote(database) : "current_database()"}
#{query_hash ? "AND queryid = #{quote(query_hash)}" : nil}
)
SELECT
query,