Class: RubyPgExtras::DiagnoseData

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_pg_extras/diagnose_data.rb

Constant Summary collapse

PG_EXTRAS_TABLE_CACHE_HIT_MIN_EXPECTED =
"0.985"
PG_EXTRAS_INDEX_CACHE_HIT_MIN_EXPECTED =
"0.985"
PG_EXTRAS_UNUSED_INDEXES_MAX_SCANS =
20
PG_EXTRAS_UNUSED_INDEXES_MIN_SIZE_BYTES =

1000000 bytes

SizeParser.to_i("1 MB")
PG_EXTRAS_NULL_INDEXES_MIN_SIZE_MB =

1 MB

1
PG_EXTRAS_NULL_MIN_NULL_FRAC_PERCENT =

50%

50
PG_EXTRAS_BLOAT_MIN_VALUE =
10
PG_EXTRAS_OUTLIERS_MIN_EXEC_RATIO =

33%

33

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.callObject



14
15
16
# File 'lib/ruby_pg_extras/diagnose_data.rb', line 14

def self.call
  new.call
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ruby_pg_extras/diagnose_data.rb', line 18

def call
  [
    :missing_fk_indexes,
    :missing_fk_constraints,
    :random_page_cost,
    :work_mem,
    :table_cache_hit,
    :index_cache_hit,
    :unused_indexes,
    :null_indexes,
    :bloat,
    :duplicate_indexes,
  ].yield_self do |checks|
    extensions_data = query_module.extensions(in_format: :hash)

    pg_stats_enabled = extensions_data.find do |el|
      el.fetch("name") == "pg_stat_statements"
    end.fetch("installed_version", false)

    ssl_info = extensions_data.find do |el|
      el.fetch("name") == "sslinfo"
    end
    ssl_info_enabled = ssl_info != nil && ssl_info.fetch("installed_version", false)

    if pg_stats_enabled
      checks = checks.concat([:outliers])
    end

    if ssl_info_enabled
      checks = checks.concat([:ssl_used])
    end

    checks
  end.map do |check|
    send(check).merge(check_name: check)
  end
end