Module: PgMonitor::SlowQueries

Defined in:
lib/pg_monitor/slow_queries.rb

Class Method Summary collapse

Class Method Details

.fetch(limit: 10) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pg_monitor/slow_queries.rb', line 7

def fetch(limit: 10)
  query = <<~SQL
    SELECT 
      query, 
      calls, 
      total_exec_time AS total_time,
      mean_exec_time AS mean_time,
      max_exec_time AS max_time
    FROM pg_stat_statements
    ORDER BY mean_exec_time DESC
    LIMIT $1;
  SQL

  result = DBConnection.connection.exec_params(query, [limit])
  result.map { |row| row }
end