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

Postgresql optimize #373

Merged
merged 3 commits into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to suggest maybe making this just VACUUM ANALYZE but I see it needs a FULL to reclaim disk space, and that's what mysql does in OPTIMIZE TABLE above

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the reclaiming of space is intended here.

end
else
raise "Don't know how to optimize for database engine: #{adapter}"
end
Expand Down