Class: PgHero::Database

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Methods::Tables

#table_caching, #table_hit_rate, #table_stats, #unused_tables

Methods included from Methods::System

#connection_stats, #cpu_usage, #free_space_stats, #rds_stats, #read_iops_stats, #replication_lag_stats, #system_stats_enabled?, #system_stats_provider, #write_iops_stats

Methods included from Methods::SuggestedIndexes

#autoindex, #best_index, #suggested_indexes, #suggested_indexes_by_query, #suggested_indexes_enabled?

Methods included from Methods::Space

#capture_space_stats, #clean_space_stats, #database_size, #relation_sizes, #relation_space_stats, #space_growth, #space_stats_enabled?, #table_sizes

Methods included from Methods::Settings

#autovacuum_settings, #settings, #vacuum_settings

Methods included from Methods::Sequences

#sequence_danger, #sequences

Methods included from Methods::Replication

#replica?, #replicating?, #replication_lag, #replication_slots

Methods included from Methods::QueryStats

#capture_query_stats, #clean_query_stats, #disable_query_stats, #enable_query_stats, #historical_query_stats_enabled?, #queries_table_exists?, #query_hash_stats, #query_stats, #query_stats_available?, #query_stats_enabled?, #query_stats_extension_enabled?, #query_stats_readable?, #query_stats_table_exists?, #reset_query_stats, #slow_queries

Methods included from Methods::Queries

#blocked_queries, #long_running_queries, #running_queries

Methods included from Methods::Maintenance

#analyze, #analyze_tables, #autovacuum_danger, #maintenance_info, #transaction_id_danger, #vacuum_progress

Methods included from Methods::Kill

#kill, #kill_all, #kill_long_running_queries

Methods included from Methods::Indexes

#duplicate_indexes, #index_bloat, #index_caching, #index_hit_rate, #index_usage, #indexes, #invalid_indexes, #last_stats_reset_time, #missing_indexes, #reset_stats, #unused_indexes

Methods included from Methods::Explain

#explain

Methods included from Methods::Constraints

#invalid_constraints

Methods included from Methods::Connections

#connection_sources, #connection_states, #connections, #total_connections

Methods included from Methods::Basic

#current_user, #database_name, #quote_ident, #server_version, #server_version_num, #ssl_used?

Constructor Details

#initialize(id, config) ⇒ Database

Returns a new instance of Database.



22
23
24
25
26
27
28
29
30
# File 'lib/pghero/database.rb', line 22

def initialize(id, config)
  @id = id
  @config = config || {}

  # preload model to ensure only one connection pool
  # this doesn't actually start any connections
  @adapter_checked = false
  @connection_model = build_connection_model
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



20
21
22
# File 'lib/pghero/database.rb', line 20

def config
  @config
end

#idObject (readonly)

Returns the value of attribute id.



20
21
22
# File 'lib/pghero/database.rb', line 20

def id
  @id
end

Instance Method Details

#aws_access_key_idObject



72
73
74
# File 'lib/pghero/database.rb', line 72

def aws_access_key_id
  config["aws_access_key_id"] || PgHero.config["aws_access_key_id"] || ENV["PGHERO_ACCESS_KEY_ID"] || ENV["AWS_ACCESS_KEY_ID"]
end

#aws_db_instance_identifierObject

environment variable is only used if no config file



85
86
87
# File 'lib/pghero/database.rb', line 85

def aws_db_instance_identifier
  @aws_db_instance_identifier ||= config["aws_db_instance_identifier"] || config["db_instance_identifier"]
end

#aws_regionObject



80
81
82
# File 'lib/pghero/database.rb', line 80

def aws_region
  config["aws_region"] || PgHero.config["aws_region"] || ENV["PGHERO_REGION"] || ENV["AWS_REGION"] || (defined?(Aws) && Aws.config[:region]) || "us-east-1"
end

#aws_secret_access_keyObject



76
77
78
# File 'lib/pghero/database.rb', line 76

def aws_secret_access_key
  config["aws_secret_access_key"] || PgHero.config["aws_secret_access_key"] || ENV["PGHERO_SECRET_ACCESS_KEY"] || ENV["AWS_SECRET_ACCESS_KEY"]
end

#cache_hit_rate_thresholdObject



40
41
42
# File 'lib/pghero/database.rb', line 40

def cache_hit_rate_threshold
  (config["cache_hit_rate_threshold"] || PgHero.config["cache_hit_rate_threshold"] || PgHero.cache_hit_rate_threshold).to_i
end

#capture_query_stats?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/pghero/database.rb', line 36

def capture_query_stats?
  config["capture_query_stats"] != false
end

#explain_timeout_secObject



56
57
58
# File 'lib/pghero/database.rb', line 56

def explain_timeout_sec
  (config["explain_timeout_sec"] || PgHero.config["explain_timeout_sec"] || PgHero.explain_timeout_sec).to_f
end

#filter_dataObject

must check keys for booleans



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/pghero/database.rb', line 95

def filter_data
  unless defined?(@filter_data)
    @filter_data =
      if config.key?("filter_data")
        config["filter_data"]
      elsif PgHero.config.key?("filter_data")
        PgHero.config.key?("filter_data")
      else
        PgHero.filter_data
      end

    if @filter_data
      begin
        require "pg_query"
      rescue LoadError
        raise Error, "pg_query required for filter_data"
      end
    end
  end

  @filter_data
end

#gcp_database_idObject

environment variable is only used if no config file



90
91
92
# File 'lib/pghero/database.rb', line 90

def gcp_database_id
  @gcp_database_id ||= config["gcp_database_id"]
end

#index_bloat_bytesObject



68
69
70
# File 'lib/pghero/database.rb', line 68

def index_bloat_bytes
  (config["index_bloat_bytes"] || PgHero.config["index_bloat_bytes"] || 100.megabytes).to_i
end

#long_running_query_secObject



60
61
62
# File 'lib/pghero/database.rb', line 60

def long_running_query_sec
  (config["long_running_query_sec"] || PgHero.config["long_running_query_sec"] || PgHero.long_running_query_sec).to_i
end

#nameObject



32
33
34
# File 'lib/pghero/database.rb', line 32

def name
  @name ||= @config["name"] || id.titleize
end

#slow_query_callsObject



52
53
54
# File 'lib/pghero/database.rb', line 52

def slow_query_calls
  (config["slow_query_calls"] || PgHero.config["slow_query_calls"] || PgHero.slow_query_calls).to_i
end

#slow_query_msObject



48
49
50
# File 'lib/pghero/database.rb', line 48

def slow_query_ms
  (config["slow_query_ms"] || PgHero.config["slow_query_ms"] || PgHero.slow_query_ms).to_i
end

#total_connections_thresholdObject



44
45
46
# File 'lib/pghero/database.rb', line 44

def total_connections_threshold
  (config["total_connections_threshold"] || PgHero.config["total_connections_threshold"] || PgHero.total_connections_threshold).to_i
end

#unused_index_bytesObject



64
65
66
# File 'lib/pghero/database.rb', line 64

def unused_index_bytes
  ((config["unused_index_megabytes"] || PgHero.config["unused_index_megabytes"] || 10).to_f * 1.megabyte).to_i
end