Class: PgHero::Database
- Inherits:
-
Object
- Object
- PgHero::Database
- Includes:
- Methods::Basic, Methods::Connections, Methods::Constraints, Methods::Explain, Methods::Indexes, Methods::Kill, Methods::Maintenance, Methods::Queries, Methods::QueryStats, Methods::Replication, Methods::Sequences, Methods::Settings, Methods::Space, Methods::SuggestedIndexes, Methods::System, Methods::Tables, Methods::Users
- Defined in:
- lib/pghero/database.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #aws_access_key_id ⇒ Object
-
#aws_db_instance_identifier ⇒ Object
environment variable is only used if no config file.
- #aws_region ⇒ Object
- #aws_secret_access_key ⇒ Object
-
#azure_resource_id ⇒ Object
environment variable is only used if no config file.
- #cache_hit_rate_threshold ⇒ Object
- #capture_query_stats? ⇒ Boolean
- #explain_timeout_sec ⇒ Object
-
#filter_data ⇒ Object
must check keys for booleans.
-
#gcp_database_id ⇒ Object
environment variable is only used if no config file.
-
#index_bloat_bytes ⇒ Object
defaults to 100 megabytes.
-
#initialize(id, config) ⇒ Database
constructor
A new instance of Database.
- #long_running_query_sec ⇒ Object
- #name ⇒ Object
- #slow_query_calls ⇒ Object
- #slow_query_ms ⇒ Object
- #total_connections_threshold ⇒ Object
Methods included from Methods::Users
Methods included from Methods::Tables
#table_caching, #table_hit_rate, #table_stats, #unused_tables
Methods included from Methods::System
#azure_stats, #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
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?, #missing_query_stats_columns, #query_hash_stats, #query_stats, #query_stats_available?, #query_stats_enabled?, #query_stats_extension_enabled?, #query_stats_readable?, #query_stats_table_exists?, #reset_instance_query_stats, #reset_query_stats, #slow_queries, #supports_query_hash?
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
Methods included from Methods::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.
23 24 25 26 27 28 29 30 31 |
# File 'lib/pghero/database.rb', line 23 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
#config ⇒ Object (readonly)
Returns the value of attribute config.
21 22 23 |
# File 'lib/pghero/database.rb', line 21 def config @config end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
21 22 23 |
# File 'lib/pghero/database.rb', line 21 def id @id end |
Instance Method Details
#aws_access_key_id ⇒ Object
70 71 72 |
# File 'lib/pghero/database.rb', line 70 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_identifier ⇒ Object
environment variable is only used if no config file
83 84 85 |
# File 'lib/pghero/database.rb', line 83 def aws_db_instance_identifier @aws_db_instance_identifier ||= config["aws_db_instance_identifier"] || config["db_instance_identifier"] end |
#aws_region ⇒ Object
78 79 80 |
# File 'lib/pghero/database.rb', line 78 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_key ⇒ Object
74 75 76 |
# File 'lib/pghero/database.rb', line 74 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 |
#azure_resource_id ⇒ Object
environment variable is only used if no config file
93 94 95 |
# File 'lib/pghero/database.rb', line 93 def azure_resource_id @azure_resource_id ||= config["azure_resource_id"] end |
#cache_hit_rate_threshold ⇒ Object
41 42 43 |
# File 'lib/pghero/database.rb', line 41 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
37 38 39 |
# File 'lib/pghero/database.rb', line 37 def capture_query_stats? config["capture_query_stats"] != false end |
#explain_timeout_sec ⇒ Object
57 58 59 |
# File 'lib/pghero/database.rb', line 57 def explain_timeout_sec (config["explain_timeout_sec"] || PgHero.config["explain_timeout_sec"] || PgHero.explain_timeout_sec).to_f end |
#filter_data ⇒ Object
must check keys for booleans
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/pghero/database.rb', line 98 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_id ⇒ Object
environment variable is only used if no config file
88 89 90 |
# File 'lib/pghero/database.rb', line 88 def gcp_database_id @gcp_database_id ||= config["gcp_database_id"] end |
#index_bloat_bytes ⇒ Object
defaults to 100 megabytes
66 67 68 |
# File 'lib/pghero/database.rb', line 66 def index_bloat_bytes (config["index_bloat_bytes"] || PgHero.config["index_bloat_bytes"] || 104857600).to_i end |
#long_running_query_sec ⇒ Object
61 62 63 |
# File 'lib/pghero/database.rb', line 61 def long_running_query_sec (config["long_running_query_sec"] || PgHero.config["long_running_query_sec"] || PgHero.long_running_query_sec).to_i end |
#name ⇒ Object
33 34 35 |
# File 'lib/pghero/database.rb', line 33 def name @name ||= @config["name"] || id.titleize end |
#slow_query_calls ⇒ Object
53 54 55 |
# File 'lib/pghero/database.rb', line 53 def slow_query_calls (config["slow_query_calls"] || PgHero.config["slow_query_calls"] || PgHero.slow_query_calls).to_i end |
#slow_query_ms ⇒ Object
49 50 51 |
# File 'lib/pghero/database.rb', line 49 def slow_query_ms (config["slow_query_ms"] || PgHero.config["slow_query_ms"] || PgHero.slow_query_ms).to_i end |
#total_connections_threshold ⇒ Object
45 46 47 |
# File 'lib/pghero/database.rb', line 45 def total_connections_threshold (config["total_connections_threshold"] || PgHero.config["total_connections_threshold"] || PgHero.total_connections_threshold).to_i end |