ruby on rails - Heroku - Trouble with migrating from Sqlite to Postgres -



ruby on rails - Heroku - Trouble with migrating from Sqlite to Postgres -

i built rails application built in database sqlite 3. have been trying time application deployed heroku. understood heroku's preferred database postgres went through problem of changing application's database sqlite postgres.

here gemfile, specifies have 'pg' installed instead of sqlite.

source 'https://rubygems.org' # bundle border rails instead: gem 'rails', github: 'rails/rails' ruby '2.1.0' gem 'rails', '4.1.1' grouping :development, :test gem 'pg', '0.17.1' gem 'rspec-rails', '3.0.1' end grouping :test gem 'selenium-webdriver', '2.35.1' gem 'capybara', '2.1.0' end gem 'sass-rails', '~> 4.0.2' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.0.0' gem 'sprockets-rails', '~> 2.1.3' gem 'bootstrap-sass', '3.1.1.1' # see https://github.com/sstephenson/execjs#readme more supported runtimes # gem 'therubyracer', platforms: :ruby gem 'jquery-rails' gem 'turbolinks' gem 'jbuilder', '~> 2.1.1' grouping :doc # bundle exec rake doc:rails generates api under doc/api. gem 'sdoc', require: false end # utilize activemodel has_secure_password gem 'bcrypt', '~> 3.1.7' # utilize unicorn app server # gem 'unicorn' # utilize capistrano deployment # gem 'capistrano', group: :development # utilize debugger # gem 'debugger', group: [:development, :test]

i have installed gem pg many times ensure it's installed. running psql --version gives me following

psql (postgresql) 9.3.4

running psql shows me directory

/usr/local/bin/psql

in converting sqlite postgres, updated database.yml file best could.

# sqlite version 3.x # gem install sqlite3 # # ensure sqlite 3 gem defined in gemfile # gem 'sqlite3' development: adapter: postgresql encoding: unicode database: games_development pool: 5 timeout: 5000 host: localhost # warning: database defined "test" erased , # re-generated development database when run "rake". # not set db same development or production. test: adapter: postgresql database: games_test pool: 5 timeout: 5000 production: adapter: postgresql database: games_production pool: 5 timeout: 5000

as can see, changed adapter sqlite3 postgresql shown on heroku dev center web site. named database next format. appname_environement 3 environments

i added host:localhost development environment.

here output receive when running cat pg_hba.conf

# type database user address method # "local" unix domain socket connections local trust # ipv4 local connections: host 127.0.0.1/32 trust # ipv6 local connections: host ::1/128 trust # allow replication connections localhost, user # replication privilege. #local replication edited trust #host replication edited 127.0.0.1/32 trust #host replication edited ::1/128 trust

now describe problem. can deploy heroku, when running heroku open received next error message.

application error error occurred in application , page not served. please seek 1 time again in few moments. if application owner, check logs details.

my next step run heroku logs command.

2014-06-19t16:14:31.269890+00:00 app[web.1]: => booting webrick 2014-06-19t16:14:31.269894+00:00 app[web.1]: => rails 4.1.1 application starting in production on http://0.0.0.0:36743 2014-06-19t16:14:31.269896+00:00 app[web.1]: => run `rails server -h` more startup options 2014-06-19t16:14:31.269898+00:00 app[web.1]: => notice: server listening on interfaces (0.0.0.0). consider using 127.0.0.1 (--binding option) 2014-06-19t16:14:31.269899+00:00 app[web.1]: => ctrl-c shutdown server 2014-06-19t16:14:31.269901+00:00 app[web.1]: exiting 2014-06-19t16:14:32.519139+00:00 heroku[web.1]: state changed starting crashed 2014-06-19t16:14:32.507573+00:00 heroku[web.1]: process exited status 1 2014-06-19t16:17:43.026380+00:00 heroku[router]: at=error code=h10 desc="app crashed" method=get path="/" host=lit-anchorage-9017.herokuapp.com request_id=d2e55388-dbe6-439e-bba5-2f3f18eb3744 fwd="24.14.65.222" dyno= connect= service= status=503 bytes=

from can understand of above output, starts off running webrick server in production development. know 'pg' gem in development , test environments indicated in gemfile. think problem. output says server exiting status 1. lastly line in gold, indicates me there problem.

reading error message, see error code h10 description "app crashed". moving forwards shows status code of 503, indicates problem server.

i tried running rake db:rollback command reset database.

pg::connectionbad: not connect server: connection refused server running on host "localhost" (127.0.0.1) , accepting tcp/ip connections on port 5432? not connect server: connection refused server running on host "localhost" (::1) , accepting tcp/ip connections on port 5432? not connect server: connection refused server running on host "localhost" (fe80::1) , accepting tcp/ip connections on port 5432? /users/edited/.rvm/gems/ruby-2.1.0/gems/activerecord- 4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:881:in `initialize' /users/edited/.rvm/gems/ruby-2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:881:in `new' /users/edited/.rvm/gems/ruby-2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:881:in `connect' /users/edited/.rvm/gems/ruby-2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize' /users/edited/.rvm/gems/ruby-2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new' /users/edited/.rvm/gems/ruby-2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'

one thing noticed indicated connection error, couldn't connect server. noticed indicated port 5432, when mutual port localhost 3000. message showed trace of problem, seems in connection_adapter/postgresql_adapter.

the above error message shown rake db:migrate, rails c-sandbox, rails c commands , rails s.

i admit when created app, created in sqlite might have caused problems. however, since need force app heroku, had alter database postgres.

to honest, sense have exhausted of options. have no selection inquire question here. advice appreciated.

hope solves issue have come across..

i have noticed haven't specified postgresql gem production environment within gemfile. have specified development , test environments.

add next gemfile:

group :production gem 'pg' gem 'rails_12factor' end

the 'rails_12factor' gem enables features static asset serving , logging in heroku have been removed rails 4.

when deploying heroku, app isn't required run postgresql in development environment in order run in production on heroku.

this resource may help out if above doesn't work. best!

https://devcenter.heroku.com/articles/getting-started-with-rails4

ruby-on-rails postgresql heroku gem bundler

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -