lib/pghero/methods/query_stats.rb in pghero-2.8.3 vs lib/pghero/methods/query_stats.rb in pghero-3.0.0

- old
+ new

@@ -54,14 +54,13 @@ def disable_query_stats execute("DROP EXTENSION IF EXISTS pg_stat_statements") true end - # TODO scope by database in PgHero 3.0 - # (add database: database_name to options) def reset_query_stats(**options) - reset_instance_query_stats(**options) + raise PgHero::Error, "Use reset_instance_query_stats to pass database" if options.delete(:database) + reset_instance_query_stats(**options, database: database_name) end # resets query stats for the entire instance # it's possible to reset stats for a specific # database, user or query hash in Postgres 12+ @@ -119,11 +118,11 @@ def supports_query_hash? server_version_num >= 90400 end - # resetting query stats will reset across the entire Postgres instance + # resetting query stats will reset across the entire Postgres instance in Postgres < 12 # this is problematic if multiple PgHero databases use the same Postgres instance # # to get around this, we capture queries for every Postgres database before we # reset query stats for the Postgres instance with the `capture_query_stats` option def capture_query_stats(raise_errors: false) @@ -145,19 +144,18 @@ query_stats = query_stats.select { |_, v| v.any? } # nothing to do return if query_stats.empty? - # use mapping, not query stats here - # TODO add option for this, and make default in PgHero 3.0 - if false # mapping.size == 1 && server_version_num >= 120000 + # reset individual databases for Postgres 12+ instance + if server_version_num >= 120000 query_stats.each do |db_id, db_query_stats| - if reset_query_stats(database: mapping[db_id], raise_errors: raise_errors) + if reset_instance_query_stats(database: mapping[db_id], raise_errors: raise_errors) insert_query_stats(db_id, db_query_stats, now) end end else - if reset_query_stats(raise_errors: raise_errors) + if reset_instance_query_stats(raise_errors: raise_errors) query_stats.each do |db_id, db_query_stats| insert_query_stats(db_id, db_query_stats, now) end end end