简体   繁体   中英

Heroku cannot connect to postgres database using Node.js

I am writing a full stack program in NodeJS, using Heroku and Postgresql. When I try to make a request through Heroku it times out. Here are the Heroku logs:

2021-04-14T23:39:01.483427+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/folders" host=damp-everglades-28835.herokuapp.com request_id=7bcfc1a9-bb04-4618-bc1b-211dcedf57c3 fwd="68.81.3.154" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=https
2021-04-14T23:39:01.489279+00:00 app[web.1]: GET /folders - - - - ms

At first, I tried to use pg version 8.xx and it would not build. I would get this error: Self signed certificate error, using pg 8.XX. Version 8 won't even deploy

    Package pg version 8.x.x not tested
    Please raise issue to support pg > 7.x.x
    [7:31:53 PM] table schemaversion does not exist - creating it.
    [7:31:53 PM] version of database is: 0
    [7:31:53 PM] migrating up to 2
    Error: self signed certificate
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1 

Searching for this error suggested adding ssl: false and here is my Postgrator.config where I tried that:

```require('dotenv').config();
module.exports = {
    "migrationsDirectory": "migrations",
    "driver": "pg", 
    "connectionString": process.env.DATABASE_URL,
    ssl: {
        rejectUnauthorized: false
      }
}```

SO, To try to fix it I downgraded to 7.4.3 and am stuck with this timeout error.

I can connect to, and modify the database directly. The backend's endpoints that do not use the database work correctly. I have triple-checked the credentials on Heroku.

Using: Node.js Heroku, javaScript, postgres

You can switch back to pg 8. .

Your connection config should include ssl.required = true like

.......
        ssl: {
            required: true,
            rejectUnauthorized: false
          }
........

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM