Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku Database Connection Properties

I'm trying to perform a relatively trivial task: I want to connect to a Heroku database. I have created the database and have been issued credentials from the Heroku site. However, when I try to connect to this database using anything besides the terminal 'heroku' command line client, I get fatal errors or cannot connect errors.

The two tools that I tried to connect with outside of the Heroku terminal application are: Navicat and IntelliJ.

The error that I receive in Navicat when trying to connect to the database is:

could not connect to server: Host is down     Is the server running on host "ec2-107-21-112-215.compute-1.amazonaws.com" and accepting     TCP/IP connections on port 5432? 

My connection settings are as follows:

Connection Name Heroku Dev Test

Host Name/IP Address ec2-107-21-112-215.compute-1.amazonaws.com

Port 5432

Navicat doesn't even seem to be making an attempt to connect to that hostname.

When I try to connect with IntelliJ, using the full credentials, I get the following error:

java.sql.SQLException: FATAL: no pg_hba.conf entry for host "75.168.4.146", user "rphbqggxeokuxl", database "dc008iqk0rq4j5", SSL off 

Again, I'm using the credentials that the Heroku application provides me with when accessing my database on their website.

Has anyone ran into this Heroku connection issue before?

like image 734
meoww- Avatar asked Jun 29 '13 05:06

meoww-


People also ask

What are connections in Heroku database?

Heroku Postgres requires SSL connections using TLS v1. 2 or higher. Most clients will connect over SSL by default, but on occasion it's necessary to set the sslmode=require parameter on a Postgres connection. Add this parameter in code rather than editing the config var directly.

Does Heroku database URL change?

The database URL is managed by Heroku and will change under some circumstances such as: User-initiated database credential rotations using heroku pg:credentials:rotate .

What is Heroku connection limit?

Maximum database connections Heroku provides managed Postgres databases. Different tiered databases have different connection limits. The Hobby Tier databases are limited to 20 connections. Standard and higher tier databases have higher limits.


1 Answers

I also had the issue with the FATAL: no pg_hba.conf entry for host error message.

I solved the connection issue to my Heroku Postgres database by adding the following to my JDBC string: &ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory.

Example

jdbc:postgresql://host:port/database?user=username&password=secret&ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory 

You will need the SSL option only if SSL is enabled for your Postgres database (which is the default).

Hint

If you want to check your database connection properties, then just run the following command with the Heroku Toolbelt: heroku pg:info --app your-heroko-appname (make sure that you have Postgres insalled to run this command in your terminal)

The pg:info command will also tell you that sslmode is set to require.

To test the database connection I recommend SQL Power Architect as it is the tool which I was using to check my solution.

like image 188
Benny Neugebauer Avatar answered Sep 25 '22 05:09

Benny Neugebauer