Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Authentication error when connecting to Heroku PostgreSQL database

I'm developing a Node.js application using PostgreSQL and hosting on Heroku. My problem is that I get an authentication error like so:

14:32:05 web.1     | { [error: no pg_hba.conf entry for host "193.40.244.196", user "username", database "database_name", SSL off] 14:32:05 web.1     |   length: 168, 14:32:05 web.1     |   name: 'error', 14:32:05 web.1     |   severity: 'FATAL', 14:32:05 web.1     |   code: '28000', 14:32:05 web.1     |   detail: undefined, 14:32:05 web.1     |   hint: undefined, 14:32:05 web.1     |   position: undefined, 14:32:05 web.1     |   internalPosition: undefined, 14:32:05 web.1     |   internalQuery: undefined, 14:32:05 web.1     |   where: undefined, 14:32:05 web.1     |   file: 'auth.c', 14:32:05 web.1     |   line: '483', 14:32:05 web.1     |   routine: 'ClientAuthentication' } 

It might be an SSL problem, but it shouldn't be as mentioned here. SSL should be supported out of the box. So I'm stumped and can only ask what might cause this error?

I'm not sure if I have to maybe edit the pg_hba.conf on my system, but I can't even find it.

like image 844
j0ntech Avatar asked Apr 23 '12 11:04

j0ntech


People also ask

How do I get Heroku Postgres credentials?

To create the credential through data.heroku.com, select the Credentials tab and click the Create Credential button. The name should reflect the purpose of the credential. In the above example, limited_user is used as the credential's username when connecting to the database.


2 Answers

Solved it by setting PGSSLMODE (http://www.postgresql.org/docs/9.0/static/libpq-envars.html) on Heroku. It tells PostgreSQL to default to SSL.

$ heroku config:set PGSSLMODE=require 
like image 178
jede Avatar answered Sep 20 '22 13:09

jede


node-postgres doesn't support SSL in it's javascript bindings, which you're using if you do:

var pg = require('pg'); 

To get SSL, you need to use the native binding by doing this:

var pg = require('pg').native; 

You don't need to use SSL when your app is running inside Heroku, you only need to use SSL to connect remotely (when your app is running locally).

like image 38
matt Avatar answered Sep 20 '22 13:09

matt