Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8337365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:17:05+00:00 2026-06-09T04:17:05+00:00

If I have a DATABASE_URL, is it possible to connect to it from localhost?

  • 0

If I have a DATABASE_URL, is it possible to connect to it from localhost? I’m using the following code:

db = URI.parse(database_url)
connection = ActiveRecord::Base.establish_connection(
                                                     :adapter  => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
                                                     :host     => db.host,
                                                     :username => db.user,
                                                     :password => db.password,
                                                     :database => db.path[1..-1],
                                                     :encoding => 'utf8'
                                                     )

When running the code from my pc, I keep getting errors like:

could not connect to server: Connection timed out
Is the server running on host some_host.amazonaws.com and accepting
    TCP/IP connections on port 5432?

I’m using the same code to share a database between two apps that are running on Heroku and it works. This leads me to believe that connecting to a Heroku database is restricted unless you perform it from a Heroku host. Is that true?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:17:06+00:00Added an answer on June 9, 2026 at 4:17 am

    Indeed SSL is required for outside connections. The underlying postgres adapter can be forced to use SSL with the sslmode=require parameter. You can pass arbitrary parameters down from the ActiveRecord connection options, like so:

    ActiveRecord::Base.establish_connection(
      adapter:  'postgresql', 
      host:     'host', 
      username: 'user', 
      password: 'pass', 
      database: 'database_name', 
      encoding: 'utf-8',
      port:     '5432', # could be a non-standard port
      sslmode:  'require' # force SSL
    )
    

    I’ve verified this locally, and here’s a full session showing it work. Please make sure you’re not mistyping anything:

    heroku pg:credentials yellow -a my-app                                                               Connection info string:
       "dbname=ddbolrs4g89dsi host=ec2-23-21-91-108.compute-1.amazonaws.com port=5432 user=itkdrxzjmwcjtw password=wU-4tT3YbF8AZ3U5kwu-2KYPEX ssl
    mode=require"
    $ irb
    > require 'active_record'
     => true
    > ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: 'ddbolrs4g89dsi', host: 'ec2-23-21-91-108.compute-1.amazonaws.com', username: 'itkdrxzjmwcjtw', password: 'wU-4tT3YbF8AZ3U5kwu-2KYPEX', sslmodel: 'require')
     => #<ActiveRecord::ConnectionAdapters::ConnectionPool:0x007f7f9ba6f0f0 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0x007f7f9ba6f078>, @spec=#<ActiveRecord::Base::ConnectionSpecification:0x007f7f9ba64150 @config={:adapter=>"postgresql", :database=>"ddbolrs4g89dsi", :host=>"ec2-23-21-91-108.compute-1.amazonaws.com", :username=>"itkdrxzjmwcjtw", :password=>"wU-4tT3YbF8AZ3U5kwu-2KYPEX", :sslmodel=>"require"}, @adapter_method="postgresql_connection">, @reserved_connections={}, @queue=#<MonitorMixin::ConditionVariable:0x007f7f9ba6f000 @monitor=#<ActiveRecord::ConnectionAdapters::ConnectionPool:0x007f7f9ba6f0f0 ...>, @cond=#<ConditionVariable:0x007f7f9ba6efd8 @waiters=[], @waiters_mutex=#<Mutex:0x007f7f9ba6ef88>>>, @timeout=5, @size=5, @connections=[], @automatic_reconnect=true>
    > ActiveRecord::Base.connection.execute("SELECT version()").first
     => {"version"=>"PostgreSQL 9.1.4 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3, 64-bit"} 
    > exit
    $ # remove db, leaked creds ^
    $ heroku addons:remove HEROKU_POSTGRESQL_YELLOW -a my-app --confirm my-app 
    Removing HEROKU_POSTGRESQL_YELLOW on my-app... done, v490 (free)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following code that generate some images with urls associated from database:
In pom.xml I have (taken from http://struberg.wordpress.com/2012/05/10/using-jpa-in-real-projects-part-1/ ): <properties> <openjpa.sql.action>refresh</openjpa.sql.action> <database.driver.name>org.postgresql.Driver</database.driver.name> <database.connection.url>jdbc:postgresql://myURL</database.connection.url> <database.user>user</database.user> <database.password>password</database.password>
Is it possible to create a MySQL database from Java? I have only seen
I have this working query that outputs URL and click counts from database. <?php
I have a URL from frontend access to the database. https://db.blabla.com Is this enough
I have an AJAX request (using JQuery) that calls a PHP script which does
Is it possible to Delimit data in a mysql database row? I have data
I have an url with the following format: domain/product.php?name=product a Now I need to
Is it possible to have the same session be active across multiple open windows
I'm calling a classic .asp page from jquery to return a list (using JSONP).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.