Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #373 from ZeroPointEnergy/postgresql_optimize
Browse files Browse the repository at this point in the history
Postgresql optimize
  • Loading branch information
ZeroPointEnergy authored Sep 13, 2018
2 parents c00a52c + c3b4ebc commit d966c60
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Contributors
* Nick Fagerlund <[email protected]>
* Nick Lewis <[email protected]>
* Nigel Kersten <[email protected]>
* Pascal Vibet <[email protected]>
* Patrick Carlisle <[email protected]>
* Paul Berry <[email protected]>
* Peter Meier <[email protected]>
Expand Down
14 changes: 11 additions & 3 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bundle install --deployment
````
* You need to create a secret for production and either set it via environment variable:
`export SECRET_KEY_BASE=$(bundle exec rails secret)`
or follow the instructions in config/secrets.yml to setup an encrypted secret.
or follow the instructions in config/secrets.yml to setup an encrypted secret.
* Setup database and pre-compile assets
````
RAILS_ENV=production bundle exec rake db:setup && \
Expand All @@ -96,9 +96,17 @@ precompile assets for production using:

* `SECRET_KEY_BASE=none RAILS_ENV=production bundle exec rails assets:precompile`

Dashboard will keep all reports in the database. If your infrastructure is big the database will
eventually become very large (more than 50GB). To periodically purge old reports (~ once per day)
and optimize the database tables (~ once per month) it is recommended to run the following tasks
periodically:

* `SECRET_KEY_BASE=none RAILS_ENV=production bundle exec rails reports:prune upto=20 unit=day`
* `SECRET_KEY_BASE=none RAILS_ENV=production bundle exec rails db:raw:optimize`

Contributing
------------

To contribute to this project, please read [CONTRIBUTING](CONTRIBUTING.md).
A list of contributors is found in [CONTRIBUTORS](CONTRIBUTORS.md). Thanks!
To contribute to this project, please read [CONTRIBUTING](CONTRIBUTING.md).
A list of contributors is found in [CONTRIBUTORS](CONTRIBUTORS.md). Thanks!
This project uses the [Silk icons](http://www.famfamfam.com/lab/icons/silk/) by Mark James. Thank you!
8 changes: 7 additions & 1 deletion lib/tasks/db_raw.rake
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,16 @@ namespace :db do
case adapter
when 'mysql', 'mysql2'
puts "Optimizing tables, this may take a while:"
for table in ActiveRecord::Base.connection.select_values('SHOW TABLES').sort
for table in ActiveRecord::Base.connection.tables.sort
puts "* #{table}"
ActiveRecord::Base.connection.execute("OPTIMIZE TABLE #{table}")
end
when 'postgresql'
puts "Optimizing tables, this may take a while:"
for table in ActiveRecord::Base.connection.tables.sort
puts "* #{table}"
ActiveRecord::Base.connection.execute("VACUUM FULL ANALYZE #{table}")
end
else
raise "Don't know how to optimize for database engine: #{adapter}"
end
Expand Down

0 comments on commit d966c60

Please sign in to comment.