Trouble connecting Postgresql to Rails


#1

#2

what about it doesn’t work?


#3

This is before using that page and will give you and after!!

could not connect to server: Connection refused Is the server running locally and accepting connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.5432”?
Extracted source (around line #651):

649
650
651
652
653
654

    # connected server's characteristics.
    def connect
      @connection = PGconn.connect(@connection_parameters)

      # Money type has a fixed precision of 10 in PostgreSQL 8.2 and below, and as of
      # PostgreSQL 8.3 it has a fixed precision of 19. PostgreSQLColumn.extract_precision

Rails.root: /home/ubuntu/workspace/my_app
Application Trace | Framework Trace | Full Trace

activerecord (4.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:651:in initialize' activerecord (4.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:651:innew’
activerecord (4.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:651:in connect' activerecord (4.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:242:ininitialize’
activerecord (4.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:44:in new' activerecord (4.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:44:inpostgresql_connection’
activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in new_connection' activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:448:incheckout_new_connection’
activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in acquire_connection' activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:349:inblock in checkout’
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/monitor.rb:214:in mon_synchronize' activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:348:incheckout’
activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in block in connection' /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/monitor.rb:214:inmon_synchronize’
activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in connection' activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:571:inretrieve_connection’
activerecord (4.2.6) lib/active_record/connection_handling.rb:113:in retrieve_connection' activerecord (4.2.6) lib/active_record/connection_handling.rb:87:inconnection’
activerecord (4.2.6) lib/active_record/migration.rb:383:in connection' activerecord (4.2.6) lib/active_record/migration.rb:370:incall’
actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:29:in block in call' activesupport (4.2.6) lib/active_support/callbacks.rb:88:inrun_callbacks’
activesupport (4.2.6) lib/active_support/callbacks.rb:778:in _run_call_callbacks' activesupport (4.2.6) lib/active_support/callbacks.rb:81:inrun_callbacks’
actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:27:in call' actionpack (4.2.6) lib/action_dispatch/middleware/reloader.rb:73:incall’
actionpack (4.2.6) lib/action_dispatch/middleware/remote_ip.rb:78:in call' actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:17:incall’
web-console (2.3.0) lib/web_console/middleware.rb:20:in block in call' web-console (2.3.0) lib/web_console/middleware.rb:18:incatch’
web-console (2.3.0) lib/web_console/middleware.rb:18:in call' actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:incall’
railties (4.2.6) lib/rails/rack/logger.rb:38:in call_app' railties (4.2.6) lib/rails/rack/logger.rb:20:inblock in call’
activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in block in tagged' activesupport (4.2.6) lib/active_support/tagged_logging.rb:26:intagged’
activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in tagged' railties (4.2.6) lib/rails/rack/logger.rb:20:incall’
actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:in call' rack (1.6.4) lib/rack/methodoverride.rb:22:incall’
rack (1.6.4) lib/rack/runtime.rb:18:in call' activesupport (4.2.6) lib/active_support/cache/strategy/local_cache_middleware.rb:28:incall’
rack (1.6.4) lib/rack/lock.rb:17:in call' actionpack (4.2.6) lib/action_dispatch/middleware/static.rb:120:incall’
rack (1.6.4) lib/rack/sendfile.rb:113:in call' railties (4.2.6) lib/rails/engine.rb:518:incall’
railties (4.2.6) lib/rails/application.rb:165:in call' rack (1.6.4) lib/rack/lock.rb:17:incall’
rack (1.6.4) lib/rack/content_length.rb:15:in call' rack (1.6.4) lib/rack/handler/webrick.rb:88:inservice’
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:140:in service' /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:96:inrun’
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread’


#4

This is after.

FATAL: database “my_app_development” does not exist
Extracted source (around line #661):

659
660
661
662
663
664

    rescue ::PG::Error => error
      if error.message.include?("does not exist")
        raise ActiveRecord::NoDatabaseError.new(error.message, error)
      else
        raise
      end

Rails.root: /home/ubuntu/workspace/my_app
Application Trace | Framework Trace | Full Trace

activerecord (4.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:661:in rescue in connect' activerecord (4.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:651:inconnect’
activerecord (4.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:242:in initialize' activerecord (4.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:44:innew’
activerecord (4.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:44:in postgresql_connection' activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:438:innew_connection’
activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in checkout_new_connection' activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:422:inacquire_connection’
activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in block in checkout' /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/monitor.rb:214:inmon_synchronize’
activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in checkout' activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:263:inblock in connection’
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/monitor.rb:214:in mon_synchronize' activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:262:inconnection’
activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in retrieve_connection' activerecord (4.2.6) lib/active_record/connection_handling.rb:113:inretrieve_connection’
activerecord (4.2.6) lib/active_record/connection_handling.rb:87:in connection' activerecord (4.2.6) lib/active_record/migration.rb:383:inconnection’
activerecord (4.2.6) lib/active_record/migration.rb:370:in call' actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:29:inblock in call’
activesupport (4.2.6) lib/active_support/callbacks.rb:88:in __run_callbacks__' activesupport (4.2.6) lib/active_support/callbacks.rb:778:in_run_call_callbacks’
activesupport (4.2.6) lib/active_support/callbacks.rb:81:in run_callbacks' actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:27:incall’
actionpack (4.2.6) lib/action_dispatch/middleware/reloader.rb:73:in call' actionpack (4.2.6) lib/action_dispatch/middleware/remote_ip.rb:78:incall’
actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:17:in call' web-console (2.3.0) lib/web_console/middleware.rb:20:inblock in call’
web-console (2.3.0) lib/web_console/middleware.rb:18:in catch' web-console (2.3.0) lib/web_console/middleware.rb:18:incall’
actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in call' railties (4.2.6) lib/rails/rack/logger.rb:38:incall_app’
railties (4.2.6) lib/rails/rack/logger.rb:20:in block in call' activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:inblock in tagged’
activesupport (4.2.6) lib/active_support/tagged_logging.rb:26:in tagged' activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:intagged’
railties (4.2.6) lib/rails/rack/logger.rb:20:in call' actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:incall’
rack (1.6.4) lib/rack/methodoverride.rb:22:in call' rack (1.6.4) lib/rack/runtime.rb:18:incall’
activesupport (4.2.6) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in call' rack (1.6.4) lib/rack/lock.rb:17:incall’
actionpack (4.2.6) lib/action_dispatch/middleware/static.rb:120:in call' rack (1.6.4) lib/rack/sendfile.rb:113:incall’
railties (4.2.6) lib/rails/engine.rb:518:in call' railties (4.2.6) lib/rails/application.rb:165:incall’
rack (1.6.4) lib/rack/lock.rb:17:in call' rack (1.6.4) lib/rack/content_length.rb:15:incall’
rack (1.6.4) lib/rack/handler/webrick.rb:88:in service' /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:140:inservice’
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:96:in run' /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/webrick/server.rb:296:inblock in start_thread’


#5

The only way I can get anything to work is install everything from a web page, as if I was installing Ruby on rails on my personal computer with Postgresql.

The cloud IDE will not except certain commands in the command line if I install from the Cloud9 site, only from another URL ???

What’s up with that ???


#6

These commands wouldn’t work from installing from the Cloud9 IDE, but installing Ruby on Rails from another site it worked, by installing with their commands.
Maybe I am missing something on the Cloud9 site ???

bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rails s -b $IP -p $PORT


#7

Maybe you want to take a look at this: https://github.com/Aerogami/guides/wiki/Cloud9-workspace-setup-with-Rails-and-Postgresql


#8

Thanks for following up on this. Please do your best to include a descriptive title for your post as well as details when you solve the issue. Then others can learn from you :wink:


#9

Thanks for the reply, but none of that is the issue, it was the database.yml file, it generated a my_app_development and my_app_test, I just needed to delete them and then rake db:create and rake db:migrate before starting rails server, but started postgresql first with sudo service postgresql start.


#10

I had a similar issue, but instead of deleting anything from the database.yml, I just started the postresql with sudo service postgresql start prior to starting the rails server.