Class: Gitlab::Database::Migrations::Observers::QueryStatistics
- Inherits:
-
MigrationObserver
- Object
- MigrationObserver
- Gitlab::Database::Migrations::Observers::QueryStatistics
- Includes:
- SchemaHelpers
- Defined in:
- lib/gitlab/database/migrations/observers/query_statistics.rb
Overview
This observer gathers statistics from the pg_stat_statements extension. Notice that this extension is not installed by default. In case it cannot be found, the observer does nothing and doesn’t throw an error.
Instance Attribute Summary
Attributes inherited from MigrationObserver
#connection, #observation, #output_dir
Instance Method Summary collapse
Methods included from SchemaHelpers
#assert_not_in_transaction_block, #create_comment, #create_trigger, #create_trigger_function, #drop_function, #drop_trigger, #function_exists?, #object_name, #tmp_table_name, #trigger_exists?
Methods inherited from MigrationObserver
Constructor Details
This class inherits a constructor from Gitlab::Database::Migrations::Observers::MigrationObserver
Instance Method Details
#before ⇒ Object
13 14 15 16 17 |
# File 'lib/gitlab/database/migrations/observers/query_statistics.rb', line 13 def before return unless enabled? connection.execute('select pg_stat_statements_reset()') end |
#record ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gitlab/database/migrations/observers/query_statistics.rb', line 19 def record return unless enabled? observation.query_statistics = connection.execute(<<~SQL) SELECT query, calls, total_time, max_time, mean_time, rows FROM pg_stat_statements WHERE pg_get_userbyid(userid) = current_user ORDER BY total_time DESC SQL end |