Question

Rails with Postgresql: Problem running rake db:migrate in production

I have built a rails app on my local machine and would like to deploy it, following the tutorial here: https://www.digitalocean.com/community/tutorials/how-to-launch-your-ruby-on-rails-app-with-the-digitalocean-one-click-image

However, after uploading the whole app through SFTP, creating a postgresql user named ‘postgres’ (I did this to get around the peer authentication error), running the command RAILS_ENV=production rake db:migrate as the UNIX user postgres gave me the following errors:

Rails Error: Unable to access log file. Please ensure that /home/rails/log/production.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed. rake aborted! Errno::EACCES: Permission denied - /home/rails/db/schema.rb

I have spent quite a bit of time googling around but no luck. Please help.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

The issue you’re seeing is due to the fact that you are running the command as the user postgres who doesn’t have permissions to access /home/rails/db/schema.rb Instead of running rake as the UNIX user postgres, create a postgres user/password for your Rails app:

sudo -u postgres psql
create role myapp_user with createdb login password 'db_password';

Then in your database.yml file:

development:
  adapter: postgresql
  encoding: unicode
  database: myapp_development
  pool: 5
  username: myapp_user
  password: db_password

test:
  adapter: postgresql
  encoding: unicode
  database: myapp_test
  pool: 5
  username: myapp_user
  password: db_password

production:
  adapter: postgresql
  encoding: unicode
  database: myapp_test
  pool: 5
  username: myapp_user
  password: db_password

You need to change app folder files permission as:

sudo chown -R jsingh /var/www/

@asb I am having the same issue even after following this solution. it still says:

deploy@TTP:/srv/ttp$ rake db:migrate
rake aborted!
Errno::EACCES: Permission denied @ rb_sysopen - /srv/ttp/db/schema.rb
/usr/local/rvm/gems/ruby-2.2.2/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:236:in `initialize'
/usr/local/rvm/gems/ruby-2.2.2/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:236:in `open'
/usr/local/rvm/gems/ruby-2.2.2/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:236:in `block (3 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.2.2/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:50:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.2.2/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:45:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:schema:dump
(See full trace by running task with --trace)

Can you help me on this.