-
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This does the work to enable historical query stats in PgHero, but the Postgres instance backing the service must also be configured, see: https://github.com/ankane/pghero/blob/master/guides/Rails.md#query-stats We are: - adding the tables to store stats - setting up a GoodJob cron job to collect the stats and clean old ones (the demo app generates a lot of queries) For reference, the recommended settings for `postgres.conf`: ``` shared_preload_libraries = 'pg_stat_statements' pg_stat_statements.track = all pg_stat_statements.max = 10000 track_activity_query_size = 2048 ``` See: https://github.com/ankane/pghero/blob/master/guides/Query-Stats.md
- Loading branch information
Showing
4 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class PgHeroMaintenanceJob < ApplicationJob | ||
include GoodJob::ActiveJobExtensions::Concurrency | ||
|
||
good_job_control_concurrency_with( | ||
key: "pg_hero_maintenance", | ||
total_limit: 1 | ||
) | ||
|
||
discard_on StandardError | ||
|
||
def perform | ||
PgHero.capture_query_stats | ||
PgHero.clean_query_stats | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
demo/db/migrate/20240321162554_create_pghero_query_stats.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreatePgheroQueryStats < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :pghero_query_stats do |t| | ||
t.text :database | ||
t.text :user | ||
t.text :query | ||
t.integer :query_hash, limit: 8 | ||
t.float :total_time | ||
t.integer :calls, limit: 8 | ||
t.timestamp :captured_at | ||
end | ||
|
||
add_index :pghero_query_stats, [:database, :captured_at] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters