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.

Cannot connect local PostgreSQL DB

See original GitHub issue

I connect my PostgreSQL local database in Node.js server using pg.

All worked fine, but suddenly it stopped to work.

This is my code: const {Pool} = require('pg') const connectionString = process.env.DATABASE_URL; const ssl = process.env.NODE_ENV == 'production' ? '?ssl=true' : ''; const pool = new Pool({ connectionString: connectionString + ssl });

const db = { pool: pool, test: async () => { try { console.log('before connection'); let result = await pool.query('SELECT $1::text as status', ['connected']); console.log('connected') return result.rows[0].status; } catch (error) { console.error('Unable to connect to the database:', error); return null; } } }

module.exports = db;

It stuck on pool.query. ‘before connection’ is logged, no error is thrown.

The very same code works fine with my remote db, and I can connect the local db with pgAdmin.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
charmandercommented, Jul 16, 2020

You don’t need to downgrade Node, just upgrade pg to the latest version.

0reactions
charmandercommented, Jul 16, 2020

Duplicate of #2275

Read more comments on GitHub >

github_iconTop Results From Across the Web

PostgreSQL: Why psql can't connect to server? - Stack Overflow
34 Answers 34 · Step 1: Running pg_lsclusters will list all the Postgres clusters running on your device · Step 2: Restart the...
Read more >
PostgreSQL is running locally but I cannot connect. Why?
I had to create the directory /var/pgsql_socket , chown it to myself, and set unix_socket_directory in postgresql.conf (located in /usr/local/var/postgres ) to ...
Read more >
PostgreSQL psql: could not connect to server - nixCraft
Step # 1: Allow remote IP address to access PostgreSQL. You need to open file called /var/lib/pgsql/data/pg_hba. · Step # 2: Allow communication ......
Read more >
PostgreSQL “Could not connect to server” Error - IONOS
The PostgreSQL error “Could not connect to server: No such file or directory” usually means that PostgreSQL is not running. However, the error ......
Read more >
Cannot connect to local PostgreSQL DB #1839 - GitHub
Hello,. I'm unable to connect to my PSQL DB. I tried the following IP addresses without success: 127.0.0.1; localhost; 0.0.0.0; 192.168.
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