2

I am new to the world of Node.js, and have setup an app running on Heroku(free) using StrongLoop. I setup the heroku postgresql addon (free tier), and tried to add the datasource to StrongLoop's arc composer UI. This UI updates the server/datasources.json. When I try connecting to my datasource I get this error:

no pg_hba.conf entry for host "X.X.X.X", user "myUser", database "mydb", SSL off

I understand that the problem must be with setting up SSL on postgres. The closest StrongLoop documentation doesn't quite discuss this: https://strongloop.com/strongblog/postgresql-node-js-apis-loopback-connector/ ... Because I'm using StrongLoop rather than just straight Node.js, Heroku's documentation also left me lacking https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-node-js. I'm confused as to what I need to do exactly from here.

I have fairly simplistic newsfeed type JSON data that I manipulate with handlebars. So if it's an issue with being on the free tier, I'm open to other free suggestions with my setup. I appreciate your help.

Edit, datasources.json:

{"db":{"name":"db","connector":"memory"},
"mydb":{
"host":"myhost",
"port":####,
"url":"myamazonawsurl:####/mydbname",
"database":"mydbname",
"password":"mypw",
"name":"mydatasourcename",
"ssl":true,
"user":"myuser",
"connector":"postgresql"}}

More error details:

error: no pg_hba.conf entry for host "X.X.X.X", user "myuser", database "mydb", SSL off at 
Connection.parseE (c:\myroot\node_modules\loopback-connector-postgresql\node_modules\pg\lib\connection.js:539:11) at 
Connection.parseMessage (c:\myroot\node_modules\loopback-connector-postgresql\node_modules\pg\lib\connection.js:366:17) at 
Socket.<anonymous> (c:\myroot\node_modules\loopback-connector-postgresql\node_modules\pg\lib\connection.js:105:22) at 
Socket.emit (events.js:107:17) at readableAddChunk (_stream_readable.js:163:16) at 
Socket.Readable.push (_stream_readable.js:126:10)

5 Answers 5

5

It should be "?ssl=true" not "?sslmode=require"

"devpostgresql": {
    "url": "postgres://user:[email protected]:5432/dbname?ssl=true",
    "name": "devpostgresql",
    "connector": "postgresql"
  }
Sign up to request clarification or add additional context in comments.

Comments

3

Based on the article you've linked, you'll need to modify your datasources.json configuration to suit your Heroku environment.

Get your details from heroku pg:credentials DATABASE_URL which will spit out the below (without the place-holders I've used, of course!):

postgres://user:[email protected]:5432/your-db-name

Paste that into datasources.json:

  "accountDB": {
     "connector": "postgresql",
     "url": "postgres://user:[email protected]:5432/your-db-name?sslmode=require"
  }

The PostgreSQL docs for Loopback provide some further details - http://docs.strongloop.com/display/public/LB/PostgreSQL+connector - but the above should get you started.

7 Comments

I tried that with no luck: {"db":{"name":"db","connector":"memory"},"mydb":{"host":"myhost","port":####,"url":"myamazonawsurl:####/mydbname","database":"mydbname","password":"mypw","name":"mydatasourcename","ssl":true,"user":"myuser","connector":"postgresql"}}
Can you update your question with what you put in datasources.json? Comments don't format JSON well. If you can also post the error you get it'll help. Based on what you pasted I don't think you've entered it correctly.
yeah, sorry about that. Added them. StrongLoop's UI automatically places the connection strings in their fields in the datasources.json. I manually added the "ssl": true to the file.
Please note that url property shadows other configuration attributes. You should make them part of the url as query params, for example: "url": "postgres://user:[email protected]:5432/your-db-name?ssl=true",
right @RaymondFeng I agree it's much cleaner, but beyond adding the ssl key there is still something on heroku side that must need configuring.
|
2

Require SSL for Postgres connections by setting the following environment variable in command line:

$ export PGSSLMODE=require

Comments

1

I ran into similar problem myself and I found this solution to fix it for me. Similar to @Lieblingsfarbe's answer, but this is in Heroku CLI.

Go into Heroku CLI -> your app directory -> issue this command:

heroku config:set PGSSLMODE=require

Reference: Found it here after a few hours of trying and researching (https://stackoverflow.com/a/27732431/7430591)

1 Comment

This worked!! Thank you so much!! Heroku, if you are on here, please put this in the docs for upgrading DB plans...
0

I tried doing all above options, but in my case I was using wrong driver for postgresql.

After checking my postgresql version, which is 10.4, I had to use the gradle configuration below:

compile group: 'org.postgresql', name: 'postgresql', version: '42.2.5'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.