Class: CitizenCodeScripts::KillDbSessions
- Defined in:
- lib/citizen_code_scripts/kill_db_sessions.rb
Constant Summary
Constants included from Colorize
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Base
#app_names, #app_root, help, inherited, #initialize, load_scripts_deferred, name, run, script_classes, script_names, scripts, #staging_app_name, #step, #system!
Methods included from Colorize
Constructor Details
This class inherits a constructor from CitizenCodeScripts::Base
Class Method Details
.description ⇒ Object
2 3 4 |
# File 'lib/citizen_code_scripts/kill_db_sessions.rb', line 2 def self.description "Kills active Postgres sessions" end |
Instance Method Details
#run ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/citizen_code_scripts/kill_db_sessions.rb', line 6 def run print "Loading Rails... " require app_root.join("./config/environment") puts "done" print "Killing DB sessions... " ActiveRecord::Base.connection.execute(<<-SQL) SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE datname = current_database() AND pid <> pg_backend_pid() SQL puts "done" end |