Mohammed Mortaga
Mohammed Mortaga

Reputation: 139

Heroku PostgreSQL - could not send SSL negotiation packet: Resource temporarily unavailable

I'm using Heroku's Postgres add-on in one of my NodeJS apps. The code seems to work but any connections to the database using this module hangs and never responds with neither a success or a failure.

To investigate the issue, I tried connecting to the database through my terminal using pgcli <db url> but got the following error:

could not send SSL negotiation packet: Resource temporarily unavailable.

Further details:

Any help would be appreciated.

Upvotes: 0

Views: 3152

Answers (1)

Bergur
Bergur

Reputation: 4057

  1. Go to heroku settings, find your environmental variables.
  2. Find the DATABASE_URL variable, copy its value
  3. Go to your project add .env file and add the environmental variable there
  4. Install and follow instructions on env module .e.g https://www.npmjs.com/package/dotenv
  5. Add your connection config

.env

DATABASE_URL=verylongstring

index.js

require('dotenv').config()

const pg = require('pg'

const pgPool = new pg.Pool({
  connectionString: process.env.DATABASE_URL,
  ssl: {
    rejectUnauthorized: false
  }
})

If your using github or some other service to store your code make sure to not send the .env file with you since its only for local development. Heroku has the environmental variables in your app.

.gitignore

.env

Upvotes: 1

Related Questions