From dfe3ecb91412640ba94d0688d6fe9f5379b44610 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 19 Oct 2015 14:02:22 +1100 Subject: [PATCH] PERF: disable prepared statements see: https://github.com/rails/rails/issues/21992 --- app/controllers/admin/diagnostics_controller.rb | 13 +++++++++++++ config/database.yml | 2 ++ config/discourse_defaults.conf | 6 +++--- config/routes.rb | 1 + 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/diagnostics_controller.rb b/app/controllers/admin/diagnostics_controller.rb index bd311b42d7c..161963519ee 100644 --- a/app/controllers/admin/diagnostics_controller.rb +++ b/app/controllers/admin/diagnostics_controller.rb @@ -4,6 +4,19 @@ class Admin::DiagnosticsController < Admin::AdminController layout false skip_before_filter :check_xhr + def dump_statement_cache + statements = Post.exec_sql("select * from pg_prepared_statements").to_a + text = "" + + statements.each do |row| + text << "name: #{row["name"]} sql: #{row["statement"]}\n" + end + + text << "\n\nCOUNT #{statements.count}" + + render text: text, content_type: Mime::TEXT + end + def memory_stats text = nil diff --git a/config/database.yml b/config/database.yml index 10cd2890999..fb6d923aea2 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,4 +1,5 @@ development: + prepared_statements: false adapter: postgresql database: discourse_development min_messages: warning @@ -25,6 +26,7 @@ test: # profile db is used for benchmarking using the script/bench.rb script profile: + prepared_statements: false adapter: postgresql database: discourse_profile min_messages: warning diff --git a/config/discourse_defaults.conf b/config/discourse_defaults.conf index 4d7bbfa76fa..9488d807f7c 100644 --- a/config/discourse_defaults.conf +++ b/config/discourse_defaults.conf @@ -39,9 +39,9 @@ db_username = discourse # password used to access the db db_password = -# allow usage of prepared statements, must be disabled for -# pgpool transaction pooling -db_prepared_statements = true +# Disallow prepared statements +# see: https://github.com/rails/rails/issues/21992 +db_prepared_statements = false # hostname running the forum hostname = "www.example.com" diff --git a/config/routes.rb b/config/routes.rb index 9d6ec430b02..cc55476b0ab 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -205,6 +205,7 @@ Discourse::Application.routes.draw do get "memory_stats"=> "diagnostics#memory_stats", constraints: AdminConstraint.new get "dump_heap"=> "diagnostics#dump_heap", constraints: AdminConstraint.new + get "dump_statement_cache"=> "diagnostics#dump_statement_cache", constraints: AdminConstraint.new end # admin namespace