Created
January 25, 2016 05:36
-
-
Save ichi/56b1c379bb8697edb7c7 to your computer and use it in GitHub Desktop.
postgresのセッションぶっとばすrakeタスク。 test環境にするならRAILS_ENV=testの指定も忘れずにね。
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
# lib/tasks/postgres.rake | |
namespace :db do | |
namespace :pg do | |
namespace :session do | |
desc 'reset postgres session/connection' | |
task :reset do | |
sql = %{ | |
SELECT pg_terminate_backend(pid) | |
FROM pg_stat_activity | |
WHERE datname = '#{ActiveRecord::Base.connection_config[:database]}' | |
AND pid <> pg_backend_pid(); | |
} | |
ActiveRecord::Base.connection.execute(sql) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment