I'm just sitting here trying to deploy my app to heroku for the last 4 hours.
I just want to push my changes, but the following appears each and every time I push my changes.
rake aborted!
The driver encountered an unknown error: org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
I'm running a rails 4.0.2 application with jruby 1.7.4 and ruby 1.9.3.
I've already used this extension.
https://devcenter.heroku.com/articles/labs-user-env-compile
But it won't help either.
Here's a more detailed stack trace
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activerecord-jdbc-adapter-1.3.5/lib/arjdbc/jdbc/connection.rb:23:in `initialize'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activerecord-jdbc-adapter-1.3.5/lib/arjdbc/jdbc/adapter.rb:68:in `initialize'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activerecord-jdbc-adapter-1.3.5/lib/arjdbc/postgresql/adapter.rb:1275:in `initialize'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activerecord-jdbc-adapter-1.3.5/lib/arjdbc/jdbc/connection_methods.rb:12:in `jdbc_connection'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activerecord-jdbc-adapter-1.3.5/lib/arjdbc/postgresql/connection_methods.rb:45:in `postgresql_connection'
org/jruby/RubyBasicObject.java:1709:in `__send__'
org/jruby/RubyKernel.java:2213:in `send'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `checkout'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `connection'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activerecord-4.0.2/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activerecord-4.0.2/lib/active_record/connection_handling.rb:53:in `connection'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activerecord-4.0.2/lib/active_record/model_schema.rb:203:in `table_exists?'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activerecord-4.0.2/lib/active_record/attribute_methods.rb:123:in `attribute_method?'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activemodel-4.0.2/lib/active_model/validations/acceptance.rb:16:in `setup'
org/jruby/RubyArray.java:2651:in `reject!'
org/jruby/RubyArray.java:2614:in `reject'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activemodel-4.0.2/lib/active_model/validations/acceptance.rb:16:in `setup'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activemodel-4.0.2/lib/active_model/validations/with.rb:88:in `validates_with'
org/jruby/RubyArray.java:1617:in `each'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activemodel-4.0.2/lib/active_model/validations/with.rb:86:in `validates_with'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/vendor/bundle/jruby/1.9/gems/activemodel-4.0.2/lib/active_model/validations/acceptance.rb:51:in `validates_acceptance_of'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/app/models/user.rb:20:in `User'
/tmp/build_f358186b-fb40-492f-93f9-f05fa7b3f751/app/models/user.rb:1:in `(root)'
So this one was really really odd.
After nearly one whole day debugging I was able to solve the issue.
It has nothing to do with jRuby, nor with the active-record Adapter (you get a very similar error if you push this to heroku with a ruby-Runtime rather than a jruby-Runtime).
The issues was caused by this line in one of my models
validates_presence_of :terms_of_service
After commenting it out and pushing it to heroku again everything is fine.
Odd...
Can you try this?
Set username: systemuser, host: localhost in your YAML file
If above solution doesn't work, please refer to this link:
http://www.revsys.com/writings/postgresql/errors.html
Hope this solves your issue!
Related
While trying to deploy in the "Ruby 3.0 running on 64bit Amazon Linux 2/3.6.2" platform, both using the eb deploy command or manually uploading a zipped version of my project, it seems the Postgresql service is not running in my instance since I get the next in eb-engile.log:
2023/01/17 17:31:04.238133 [ERROR] An error occurred during execution of command [app-deploy] - [rake tasks]. Stop running the command. Error: running rake task db:migrate failed with error command bundle exec rake db:migrate failed with error Command /bin/su webapp -c bundle exec rake db:migrate failed with error exit status 1. Stderr:rake aborted!
ActiveRecord::ConnectionNotEstablished: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:83:in `rescue in new_client'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:77:in `new_client'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_handling.rb:327:in `retrieve_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_handling.rb:283:in `connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <main>'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:90:in `each'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <main>'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/opt/elasticbeanstalk/.rbenv/versions/3.0.5/bin/bundle:25:in `load'
/opt/elasticbeanstalk/.rbenv/versions/3.0.5/bin/bundle:25:in `<main>'
Caused by:
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/pg-1.2.3/lib/pg.rb:58:in `initialize'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/pg-1.2.3/lib/pg.rb:58:in `new'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/pg-1.2.3/lib/pg.rb:58:in `connect'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:78:in `new_client'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `public_send'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `new_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:926:in `checkout_new_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:905:in `try_to_checkout_new_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:866:in `acquire_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:588:in `checkout'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:428:in `connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:1128:in `retrieve_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_handling.rb:327:in `retrieve_connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/connection_handling.rb:283:in `connection'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/tasks/database_tasks.rb:237:in `migrate'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:92:in `block (3 levels) in <main>'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:90:in `each'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/activerecord-6.1.7/lib/active_record/railties/databases.rake:90:in `block (2 levels) in <main>'
/var/app/staging/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/opt/elasticbeanstalk/.rbenv/versions/3.0.5/bin/bundle:25:in `load'
/opt/elasticbeanstalk/.rbenv/versions/3.0.5/bin/bundle:25:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Although, when trying to run the /bin/su webapp -c bundle exec rake db:migrate command as root (please notice that, I am invoking bundler then as the webapp user), I get different kind of error (trying to install a missing gem?):
Bundler::PermissionError: There was an error while trying to write to
`/var/app/staging/vendor/bundle/ruby/3.0.0/cache/public_suffix-5.0.1.gem`. It is likely that you
need to grant write permissions for that path.
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/shared_helpers.rb:105:in `rescue in
filesystem_access'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/shared_helpers.rb:102:in
`filesystem_access'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/rubygems_integration.rb:479:in `block in
download_gem'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/retry.rb:40:in `run'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/retry.rb:30:in `attempt'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/rubygems_integration.rb:470:in
`download_gem'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/source/rubygems.rb:485:in `download_gem'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/source/rubygems.rb:447:in `fetch_gem'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/source/rubygems.rb:431:in
`fetch_gem_if_possible'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/source/rubygems.rb:158:in `install'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer/gem_installer.rb:54:in
`install'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer/gem_installer.rb:16:in
`install_from_spec'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer/parallel_installer.rb:155:in
`do_install'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer/parallel_installer.rb:140:in
`install_serially'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer/parallel_installer.rb:91:in
`call'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer/parallel_installer.rb:67:in
`call'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:244:in
`install_in_parallel'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:201:in `install'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:89:in `block in run'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/process_lock.rb:19:in `rescue in lock'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/process_lock.rb:15:in `lock'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:71:in `run'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/installer.rb:23:in `install'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/cli/install.rb:62:in `run'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/cli.rb:260:in `block in install'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/settings.rb:131:in `temporary'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/cli.rb:259:in `install'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/vendor/thor/lib/thor/command.rb:27:in
`run'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in
`invoke_command'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/vendor/thor/lib/thor.rb:392:in
`dispatch'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/cli.rb:34:in `dispatch'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/vendor/thor/lib/thor/base.rb:485:in
`start'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/cli.rb:28:in `start'
/opt/rubies/ruby-3.0.5/lib/ruby/gems/3.0.0/gems/bundler-2.4.1/exe/bundle:45:in `block in <top
(required)>'
/opt/rubies/ruby-3.0.5/lib/ruby/site_ruby/3.0.0/bundler/friendly_errors.rb:117:in
`with_friendly_errors'
/opt/rubies/ruby-3.0.5/lib/ruby/gems/3.0.0/gems/bundler-2.4.1/exe/bundle:33:in `<top
(required)>'
/opt/elasticbeanstalk/.rbenv/versions/3.0.5/bin/bundle:25:in `load'
/opt/elasticbeanstalk/.rbenv/versions/3.0.5/bin/bundle:25:in `<main>'
An error occurred while installing public_suffix (5.0.1), and Bundler cannot
continue.
In Gemfile:
capybara was resolved to 3.38.0, which depends on
addressable was resolved to 2.8.1, which depends on
public_suffix
It also seems the postgresql service is not installed (checked installed services starting with the "post" string):
[root#ip************ staging]# systemctl list-unit-files | grep post
postfix.service enabled
So, the question is, how do I make the eb deploy command run without failing? given that:
I see one error using eb deploy that highlights a failing rake db:migrate command but, when trying to running it manually after connecting through SSH it throws a different error; the one that mentions public_suffix. This seems unexpected.
The postgresql service should be installed in AWS's managed platform, as with previous versions
Adding a database to your Elastic Beanstalk environment
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.managing.db.html
It looks like your app is trying to connect to a local database server:
Caused by:
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
What are the contents of your config/database.yml? Is it reading environment variables that elasticbeanstalk knows to pass in? Does your RDS instance have the right access rules set up to allow connections from EB?
I've been trying to install the Consul software for a few hours. For this I use the installation instructions https://docs.consulproject.org/docs/english-documentation/introduction/local_installation
Unfortunately, I have virtually no idea about Ruby, Postgres, etc.
Unfortunately, I get an error message when I run the following commands.
rake db: create
rake db: setup
rake db: dev_seed
rake db: test: prepare
Here is the entire issue:
rake db:create
/var/lib/gems/2.7.0/gems/dry-types-0.13.3/lib/dry/types/definition.rb:31: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/var/lib/gems/2.7.0/gems/dry-types-0.13.3/lib/dry/types/options.rb:8: warning: The called method `initialize' is defined here
/var/lib/gems/2.7.0/gems/dry-types-0.13.3/lib/dry/types/decorator.rb:13: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/var/lib/gems/2.7.0/gems/dry-types-0.13.3/lib/dry/types/options.rb:8: warning: The called method `initialize' is defined here
/var/lib/gems/2.7.0/gems/dry-types-0.13.3/lib/dry/types/sum.rb:43: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/var/lib/gems/2.7.0/gems/dry-types-0.13.3/lib/dry/types/options.rb:8: warning: The called method `initialize' is defined here
warning: parser/current is loading parser/ruby27, which recognizes
warning: 2.7.2-compliant syntax, but you are running 2.7.0.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/type.rb:27: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/type/adapter_specific_registry.rb:9: warning: The called method `add_modifier' is defined here
/var/lib/gems/2.7.0/gems/acts-as-taggable-on-6.5.0/lib/acts_as_taggable_on/tagging.rb:9: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/associations.rb:1653: warning: The called method `belongs_to' is defined here
/var/lib/gems/2.7.0/gems/actionpack-5.2.4.4/lib/action_dispatch/middleware/stack.rb:37: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/var/lib/gems/2.7.0/gems/actionpack-5.2.4.4/lib/action_dispatch/middleware/static.rb:111: warning: The called method `initialize' is defined here
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
Couldn't create 'consul_development' database. Please check your configuration.
rake aborted!
PG::ConnectionBad: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
/var/lib/gems/2.7.0/gems/pg-1.0.0/lib/pg.rb:56:in `initialize'
/var/lib/gems/2.7.0/gems/pg-1.0.0/lib/pg.rb:56:in `new'
/var/lib/gems/2.7.0/gems/pg-1.0.0/lib/pg.rb:56:in `connect'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/postgresql_adapter.rb:692:in `connect'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/postgresql_adapter.rb:223:in `initialize'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `new'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `postgresql_connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:830:in `new_connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:874:in `checkout_new_connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:853:in `try_to_checkout_new_connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:814:in `acquire_connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:538:in `checkout'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:1033:in `retrieve_connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_handling.rb:90:in `connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/postgresql_database_tasks.rb:12:in `connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/postgresql_database_tasks.rb:21:in `create'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/database_tasks.rb:119:in `create'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/database_tasks.rb:139:in `block in create_current'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/database_tasks.rb:316:in `block in each_current_configuration'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/database_tasks.rb:313:in `each'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/database_tasks.rb:313:in `each_current_configuration'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/database_tasks.rb:138:in `create_current'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/railties/databases.rake:29:in `block (2 levels) in <top (required)>'
/var/lib/gems/2.7.0/gems/airbrake-5.8.1/lib/airbrake/rake/task_ext.rb:19:in `execute'
/usr/share/rubygems-integration/all/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/cli/exec.rb:74:in `load'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/cli/exec.rb:74:in `kernel_load'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/cli/exec.rb:28:in `run'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/cli.rb:463:in `exec'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/cli.rb:27:in `dispatch'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/cli.rb:18:in `start'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/exe/bundle:30:in `block in <top (required)>'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/exe/bundle:22:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
Tasks: TOP => db:create
(See full trace by running task with --trace)
Does anyone have any idea how to solve this? Thanks in advance!
This means that Postgresql isn't running so it cannot make the database.
Have you installed Postgres? If so, you can likely start the service by using:
sudo service postgresql restart
If Postgres isn't installed, you first need to install it. How to do so differs depending on your system:
https://www.postgresqltutorial.com/install-postgresql/
I have a working Ruby on Rails app (running Ruby 2.2.10p489 and Rails 4.2.5 and activerecord-sqlserver-adapter 4.2.6) on a Linux server (Amazon AMI v 2018.03 rhel fedora). It connects to an Azure database. Everything works great. But when I migrate to a different Azure database and change the credentials to point to the new database, I get a long list of unhelpful errors that looks like so:
SystemStackError: stack level too deep
from /apps/acme_dynamite/path/ruby/2.2/gems/tiny_tds-1.0.5/lib/tiny_tds/client.rb:53:in `connect'
from /apps/acme_dynamite/path/ruby/2.2/gems/tiny_tds-1.0.5/lib/tiny_tds/client.rb:53:in `initialize'
from /apps/acme_dynamite/path/ruby/2.2/gems/activerecord-sqlserver-adapter-4.2.6/lib/active_record/connection_adapters/sqlserver_adapter.rb:280:in `new'
from /apps/acme_dynamite/path/ruby/2.2/gems/activerecord-sqlserver-adapter-4.2.6/lib/active_record/connection_adapters/sqlserver_adapter.rb:280:in `dblib_connect'
from /apps/acme_dynamite/path/ruby/2.2/gems/activerecord-sqlserver-adapter-4.2.6/lib/active_record/connection_adapters/sqlserver_adapter.rb:271:in `connect'
from /apps/acme_dynamite/path/ruby/2.2/gems/activerecord-sqlserver-adapter-4.2.6/lib/active_record/connection_adapters/sqlserver_adapter.rb:59:in `initialize'
from /apps/acme_dynamite/path/ruby/2.2/gems/activerecord-sqlserver-adapter-4.2.6/lib/active_record/sqlserver_base.rb:18:in `new'
from /apps/acme_dynamite/path/ruby/2.2/gems/activerecord-sqlserver-adapter-4.2.6/lib/active_record/sqlserver_base.rb:18:in `sqlserver_connection'
from /apps/acme_dynamite/path/ruby/2.2/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
from /apps/acme_dynamite/path/ruby/2.2/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
from /apps/acme_dynamite/path/ruby/2.2/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
from /apps/acme_dynamite/path/ruby/2.2/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
from /usr/share/ruby/2.2/monitor.rb:211:in `mon_synchronize'
from /apps/acme_dynamite/path/ruby/2.2/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
from /apps/acme_dynamite/path/ruby/2.2/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
from /usr/share/ruby/2.2/monitor.rb:211:in `mon_synchronize'
from /apps/acme_dynamite/path/ruby/2.2/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
from /apps/acme_dynamite/path/ruby/2.2/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
from /apps/acme_dynamite/path/ruby/2.2/gems/activerecord-4.2.5/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
from /apps/acme_dynamite/path/ruby/2.2/gems/activerecord-4.2.5/lib/active_record/connection_handling.rb:87:in `connection'
from (irb):1
from /apps/acme_dynamite/path/ruby/2.2/gems/railties-4.2.5/lib/rails/commands/console.rb:110:in `start'
from /apps/acme_dynamite/path/ruby/2.2/gems/railties-4.2.5/lib/rails/commands/console.rb:9:in `start'
from /apps/acme_dynamite/path/ruby/2.2/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:68:in `console'
from /apps/acme_dynamite/path/ruby/2.2/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /apps/acme_dynamite/path/ruby/2.2/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
the working Azure connection looks something like:
env PRODUCTION_DATABASE_HOST="xxx.database.windows.net"
env PRODUCTION_DATABASE_PORT=1433
env PRODUCTION_DATABASE="databasename_no_dots"
env PRODUCTION_DATABASE_USERNAME="username_no_dots_or_ands"
env PRODUCTION_DATABASE_PASSWORD="supersecret"
the non-working one looks like:
env PRODUCTION_DATABASE_HOST="xxx2.database.windows.net"
env PRODUCTION_DATABASE_PORT=1433
env PRODUCTION_DATABASE="other_databasename_no_dots"
env PRODUCTION_DATABASE_USERNAME="username_no_dots_or_ands"
env PRODUCTION_DATABASE_PASSWORD="supersecret"
The problem is not connectivity or a firewall, because I can actually connect to this new Azure server using /node_modules/sql-cli. What could possibly be wrong? Some incompatibility between my version of Ruby and this other instance of Azure? I am out of ideas.
That pile of errors can be triggered from within irb just by issuing a statement like:
results = ActiveRecord::Base.connection.exec_query("SELECT 1")
UPDATE: the key to getting around this problem turned out to be the creation of a new Azure login/user (see https://azure.microsoft.com/en-us/blog/adding-users-to-your-sql-azure-database/ ). While the admin user you might be tempted to work with works fine for some database connections, in Ruby on Rails it is likely to fail in the unhelpful way described above. Trust me, you can avoid a lot of headaches if you set up some other app-specific SQL login first. All this could've been avoided had Ruby on Rails simply reported that the database user had insufficient permissions instead of getting caught in runaway recursion.
You could try:
env PRODUCTION_DATABASE_HOST="xxx2.database.windows.net"
Recently I forked and cloned a repo I am contributing to and when I run rails s I get no errors, however when I run rake db:migrate I get this.
rake aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `initialize'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `new'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_handling.rb:87:in `connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:910:in `initialize'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `new'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `up'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:785:in `migrate'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I checked out some other threads with other people who had the same problem however their solutions did not really have any luck for me.
I tried uninstalling and reinstalling PG as well as getting rid of the .PID file however it doesn't look like I seem to have one.
Any clues, pointers or advice? Thanks in advance.
This means either your database.yml file in config/ directory is not set up correctly for your environment, most likely development as it is the default or you do not have postgresql running.
If you do not have postgresql running either install it or start it up. You can check postgresql, more than likely with either:
sudo service postgresql status
or
ps -ef | grep postgres
If you do have postgresql running, then check your database.yml file and edit it appropriately, most likely something like:
development:
adapter: postgresql
encoding: unicode
database: database_name
host: localhost
username: user_name
password: password
I am pushing to an app I haven't updated in months and am running into this problem. I only changed a few variables in my code. No idea why its suddenly doing this to me.
!
! Precompiling assets failed.
!
! Push rejected, failed to compile Ruby app
To git#heroku.com:myapp.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git#heroku.com:myapp.git'
rake aborted!
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
/tmp/build_8c6e6263-c5c9-44ac-88ad-7eadb7c4c0e6/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `initialize'
/tmp/build_8c6e6263-c5c9-44ac-88ad-7eadb7c4c0e6/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `new'
/tmp/build_8c6e6263-c5c9-44ac-88ad-7eadb7c4c0e6/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `connect'
/tmp/build_8c6e6263-c5c9-44ac-88ad-7eadb7c4c0e6/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:324:in `initialize'
/tmp/build_8c6e6263-c5c9-44ac-88ad-7eadb7c4c0e6/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
/tmp/build_8c6e6263-c5c9-44ac-88ad-7eadb7c4c0e6/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
/tmp/build_8c6e6263-c5c9-44ac-88ad-7eadb7c4c0e6/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
/tmp/build_8c6e6263-c5c9-44ac-88ad-7eadb7c4c0e6/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
/tmp/build_8c6e6263-c5c9-44ac-88ad-7eadb7c4c0e6/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
/tmp/build_8c6e6263-c5c9-44ac-88ad-7eadb7c4c0e6/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
/tmp/build_8c6e6263-c5c9-44ac-88ad-7eadb7c4c0e6/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
/tmp/build_8c6e6263-c5c9-44ac-88ad-7eadb7c4c0e6/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
/tmp/build_8c6e6263-c5c9-44ac-88ad-7eadb7c4c0e6/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
/tmp/build_8c6e6263-c5c9-44ac-88ad-7eadb7c4c0e6/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
/tmp/build_8c6e6263-c5c9-44ac-88ad-7eadb7c4c0e6/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
/tmp/build_8c6e6263-c5c9-44ac-88ad-7eadb7c4c0e6/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
/tmp/build_8c6e6263-c5c9-44ac-88ad-7eadb7c4c0e6/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
/tmp/build_8c6e6263-c5c9-44ac-88ad-7eadb7c4c0e6/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/model_schema.rb:308:in `clear_cache!'
/tmp/build_8c6e6263-c5c9-44ac-88ad-7eadb7c4c0e6/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/railtie.rb:104:in `block (2 levels) in <class:Railtie>'
The most common reasons for asset recompilation issues can be found here on the heroku support page.
Based on the mention of Postgres in the error message, I would try changing the following line in your config/application.rb to false like so: config.assets.initialize_on_precompile = false.
You should prevent initializing your application and connecting to the database by ensuring that the following line is in your config/application.rb:
config.assets.initialize_on_precompile = false