chore: Set statement timeout for Postgres (#6641)
By default, Rails does not set a timeout on database statements. For example, this will run for a full day, even if your ruby process goes away. But it's configurable in the database.yml with the statement_timeout variable.
Hence we are enforcing a 14s timeout by default. Migration commands inside chatwoot will run with a 10 minutes timeout. For specific cases like migrations, we can override this timeout using the environment variable POSTGRES_STATEMENT_TIMEOUT while starting a new rails console.
Test the timeouts from the rails console using.
```
ActiveRecord::Base.connection.execute("SELECT pg_sleep(15);")
```
ref: https://github.com/ankane/the-ultimate-guide-to-ruby-timeouts#postgresql
ref: https://til.hashrocket.com/posts/b44baf657d-railspg-statement-timeout-
This commit is contained in:
@@ -362,7 +362,7 @@ EOF
|
||||
function run_db_migrations(){
|
||||
sudo -i -u chatwoot << EOF
|
||||
cd chatwoot
|
||||
RAILS_ENV=production bundle exec rails db:chatwoot_prepare
|
||||
RAILS_ENV=production POSTGRES_STATEMENT_TIMEOUT=600s bundle exec rails db:chatwoot_prepare
|
||||
EOF
|
||||
}
|
||||
|
||||
@@ -574,7 +574,7 @@ The database migrations had not run as Postgres and Redis were not installed
|
||||
as part of the installation process. After modifying the environment
|
||||
variables (in the .env file) with your external database credentials, run
|
||||
the database migrations using the below command.
|
||||
'RAILS_ENV=production bundle exec rails db:chatwoot_prepare'.
|
||||
'RAILS_ENV=production POSTGRES_STATEMENT_TIMEOUT=600s bundle exec rails db:chatwoot_prepare'.
|
||||
***************************************************************************
|
||||
|
||||
EOF
|
||||
@@ -744,7 +744,7 @@ function upgrade() {
|
||||
rake assets:precompile RAILS_ENV=production
|
||||
|
||||
# Migrate the database schema
|
||||
RAILS_ENV=production bundle exec rake db:migrate
|
||||
RAILS_ENV=production POSTGRES_STATEMENT_TIMEOUT=600s bundle exec rake db:migrate
|
||||
|
||||
EOF
|
||||
|
||||
|
||||
Reference in New Issue
Block a user