question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Heroku PostgreSQL connection problem

See original GitHub issue

Trying to do something similar to #47 (connect to postgres database on heroku). I tried to set up my connection config with the host, user, password, and database name from the $DATABASE_URL environment variable.

I’ve tried both the EC2 url and the IP address as the host.

When I set up the model node and call save, the record should be saved to the database. When I connect to psql via heroku pg and query the users table it’s empty.

The example uses Bookshelf. Let me know if I should file the issue under that repo. Although my understanding is that the connection config just gets passed to Knex.

var Bookshelf = require( 'bookshelf' );

Bookshelf.PG = Bookshelf.initialize({
  client: 'pg',
  debug: true,
  connection: {
    host     : process.env.PG_HOST || 'localhost',
    user     : process.env.PG_USER || 'postgres',
    password : process.env.PG_PASSWORD || 'postgres',
    database : process.env.PG_DB || 'db',
    charset  : 'utf8'
  }
});

var User = Bookshelf.PG.Model.extend({
  tableName: 'users',
  idAttribute: 'id'
});

var u = User.forge({email: 'test@fake.com', password: 'test'});
u.save();

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
jedecommented, May 6, 2014

I ended up here struggling with wierd connection errors on Heroku. My issue was that the connection string given by Heroku doesn’t have “?ssl=true” in the end even though Heroku requires it. This can be solved by “heroku config:set PGSSLMODE=require” which will tell the pg adapter to use SSL if the config doesn’t say anything about it. It could be the case that pg.Client and pg.connect doesn’t behave completely the same.

4reactions
olsocommented, Jun 9, 2020
import knex, { Config } from "knex";
// @ts-ignore
import knexStringcase from "knex-stringcase";

import { db, isDev } from "../config";

const config = knexStringcase({
  debug: isDev,
  client: "pg",
  connection: {
    connectionString: db,
    ssl: {
      rejectUnauthorized: false,
    },
  },
  searchPath: ["public"],
  // pool: isDev ? { max: 4 } : { min: 4 },
  asyncStackTraces: true,
} as Config) as Config;

export default knex(config);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why am I seeing connection errors for my Heroku Postgres ...
These errors indicate a failed login attempt was made to your database, which means that the connection wasn't established. It is common to...
Read more >
HEROKU POSTGRES error: Connection refused Is the server ...
It could be a problem with the proxy or firewall of the internet connection you are using. Try to connect ...
Read more >
Can't connect to Heroku PostgreSql : DBE-5662 - YouTrack
Can't connect to Heroku PostgreSql using params shown in attached files. Getting error: Connection to Heroku failed.
Read more >
Heroku Postgres Connection - Salesforce Help
Create a remote connection using the Heroku Postgres connector to sync Heroku Postgres data to CRM Analytics. ... To access Heroku Postgres in...
Read more >
Connection to Postgres on Heroku with Go - Google Groups
Has anyone successfully connected to Heroku's Postgres using a Go app? I am getting a consistent error: dial tcp 127.0.0.1:5432: connection refused.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found