Class: IndexChecker::TaskDefinition::GeneralReport

Inherits:
Base
  • Object
show all
Defined in:
lib/index_checker/task_definition/general_report.rb

Constant Summary collapse

GET_INFO_QUERY =
"SELECT tbls_stat.relname, tbls_stat.seq_scan, tbls_stat.idx_scan, (tbls_stat.seq_tup_read + tbls_stat.idx_tup_fetch) as read_actions, (tbls_stat.n_tup_ins + tbls_stat.n_tup_upd + tbls_stat.n_tup_del) as write_actions,
  idx_stat.indexrelname, pg_relation_size(idx_stat.indexrelid) AS idx_size
FROM pg_stat_all_tables AS tbls_stat INNER JOIN pg_stat_user_indexes AS idx_stat ON tbls_stat.relid = idx_stat.relid
WHERE tbls_stat.relname NOT LIKE 'pg_%'
ORDER BY tbls_stat.idx_scan ASC, tbls_stat.seq_scan DESC"

Class Method Summary collapse

Methods inherited from Base

gem_root_path, open_file_in_browser, postgres_connection, result_file_path, result_template_path, write_results_to_file

Class Method Details

.generate!Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/index_checker/task_definition/general_report.rb', line 12

def self.generate!
  connection = postgres_connection
  return if connection.nil?

  @results = connection.exec(GET_INFO_QUERY)

  write_results_to_file
  open_file_in_browser(result_file_path)
rescue PG::Error => e
  puts e.message
ensure
  connection&.close
end