Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "Error: The server does not support SSL connections" when trying to access database in localhost?

I am following Heroku's node.js tutorial to provision a Postgres database. After creating a simple table and connecting to localhost:5000/db, I get an error saying "Error: The server does not support SSL connections".

I've been searching for solutions for hours but can't seem to fix it. Your help will be greatly appreciated. Thank you!

like image 317
joshua0308 Avatar asked Jan 22 '19 05:01

joshua0308


People also ask

Can T Ping database PQ SSL is not enabled on the server?

pq: SSL is not enabled on the server By default, sslmode is set to required with lib/pq , so you need to actually specify another setting to fix this. Update your connection string to include sslmode=disable and you should be back in action.

What is promise based ORM?

Sequelize being a promise-based ORM means that it supports NodeJS promises using the bluebirdJS library internally(which is a NodeJS promise library).

Does Sequelize work with Postgres?

Sequelize is a modern TypeScript and Node. js ORM for Postgres, MySQL, MariaDB, SQLite and SQL Server, and more. Featuring solid transaction support, relations, eager and lazy loading, read replication and more.


2 Answers

Here I provide a workaround for the question, and not the title of this post. A better answer to the post overall would probably address configuring SSL for the local machine.

I arrived here trying to resolve the problem of finishing that Heroku tutorial mentioned in the question and setting up the Postgres database to work locally as well as remotely.

const pool = new Pool({
    connectionString: process.env.DATABASE_URL || 'postgresql://postgres:<your admin password>@localhost:5432/<your db name>',
    ssl: process.env.DATABASE_URL ? true : false
})

My idea is to use SSL on the app I deploy but dodge SSL altogether on the local machine. By simply skipping SSL config on the local machine I am able to concentrate my efforts on developing a working app that still uses Heroku's built in SSL.

I use the Heroku environment variables to detect their environment versus my own and I select values accordingly in the code sample above. For me this has worked both locally and remotely.

like image 134
ThisClark Avatar answered Oct 06 '22 01:10

ThisClark


This is the new form Heroku is working today in 2021, they made small corrections in the connection.

const pool = (() => {
if (process.env.NODE_ENV !== 'production') {
    return new Pool({
        connectionString: process.env.DATABASE_URL,
        ssl: false
    });
} else {
    return new Pool({
        connectionString: process.env.DATABASE_URL,
        ssl: {
            rejectUnauthorized: false
          }
    });
} })();

They changed a bit, using this way you can keep local and heroku available.

like image 32
JBarros35 Avatar answered Oct 06 '22 01:10

JBarros35