Heroku Rails 4 could not connect to server: connection refused
The accepted answer did not fully resolve this. I tried to find a solution for 2-3 hours without success, then this worked:
In your app directory.
heroku labs:enable user-env-compile
it is still failing?
heroku labs:disable user-env-compile
heroku labs:enable user-env-compile
Then it worked for me, just had to remove and do again.
The following config is no longer needed in Rails 4. Compiling assets must work without it.
config.assets.initialize_on_precompile = false
Heroku Rails deploy fails with error could not connect to server: Connection refused
See this article. The solution is to set
config.assets.initialize_on_precompile = false
Heroku: PG::ConnectionBad: could not connect to server: Connection refused
In your application.rb
file, try setting this:
config.assets.initialize_on_precompile = false
and see if that fixes your issue.
Also, if you already did not pre-provision the database for your app, you need to create one:
heroku addons:create heroku-postgresql
You can verify the database was added to your application by running:
heroku config --app your_app_name
Heroku Rails 4 could not connect to server: connection refused
The accepted answer did not fully resolve this. I tried to find a solution for 2-3 hours without success, then this worked:
In your app directory.
heroku labs:enable user-env-compile
it is still failing?
heroku labs:disable user-env-compile
heroku labs:enable user-env-compile
Then it worked for me, just had to remove and do again.
The following config is no longer needed in Rails 4. Compiling assets must work without it.
config.assets.initialize_on_precompile = false
Heroku could not connect to server: 'Connection refused' when deploying a Rails 3.2.3 app on cedar stack
Same problem here. It was working 'til yesterday.
Dedicated production databases should be operational. We're continuing recovery of shared
development databases and Crane and Kappa beta databases. Varnish remains temporarily
disabled on the Bamboo HTTP stack.
Yeah, apparently just waiting is the answer here.
Can't deploy to Heroku because the server refused the connection
Include the following in your application.rb, above the Module Appname
config.assets.initialize_on_precompile = false
And read the Heroku Labs: user-env-compile Article
PG::ConnectionBad - could not connect to server: Connection refused Sinatra server on Heroku
You don't need the other lines if you have the db url, it can be a 1 liner, and also let postgres timeout it's default, no need to set it. You probably want a larger pool size in prod. Go to the postgres database you should have added to your app in Heroku. Click on the View Credentials button. Copy the data from there to your local .env file and also add .env to your .gitignore file because you don't want to commit your private credentials to your public repo.
Then on heroku
database.yml:
development:
adapter: sqlite3
database: db/madlibs.sqlite
host: localhost
pool: 5
timeout: 5000
production:
adapter: postgresql
encoding: unicode
host: <%= ENV['DB_HOST'] %>
username: <%= ENV['DB_USERNAME'] %>
password: <%= ENV['DB_PASSWORD'] %>
port: <%= ENV['DB_PORT'] %>
database: <%= ENV['DB_NAME'] %>
pool: 25
Alternatively, you could just use 1 environment variable which concatenates all of this into a URI which would look something like
#postgresql://username:password@db-shared-us-east-1-or-something.blah:1234/db
#If you use this format you can use just a single environment variable somthinglike
production:
adapter: postgresql
encoding: unicode
url: <%= ENV['DATABASE_URI'] %>
pool: 25
In either case you will need to set whatever environment variables you'll use in your database.yml file set in your Heroku dashboard at: https://dashboard.heroku.com/apps/yourappname/settings and click on Reveal Config Vars. This is where you will set the needed vars as this is where your app will load them from. Set either the vars in my first example, or a single one as in my 2nd example. Either way should work.
Make sure you have the pg gem in your production group in Gemfile. And make sure you've set your environment variables on your heroku server.
Related Topics
How to Convert a String to a Class Method
Are the Date, Time, and Datetime Classes Necessary
(Ruby,Rails) Context of Self in Modules and Libraries...
How to Find If a String Starts with Another String in Ruby
How to Get Elapsed Time in Milliseconds in Ruby
Rails 4 How to Ignore Pending Migrations
Should One Use Dashes or Underscores When Naming a Gem with More Than One Word
Is There a "Main" Method in Ruby Like in C
How to Display a PDF in Ror (Ruby)
Ruby Dropped in Netbeans 7,How to Use It in Netbeans7
Tell the End of a .Each Loop in Ruby
Rails 6.1, Ruby 3.0.0: Tests Error as They Cannot Load Rexml
Modify Ruby Hash in Place( Rails Strong Params)
Is There a Less Intrusive Alternative to Rspec's 'Should_Receive'
Can't Get Rack-Cors Working in Rails Application