1

I'm using pg-promise (and the underlying pg-pool lib).

When I pull the plug on my pg database briefly (break TCP connections), I get connect ETIMEDOUT errors (expected) however it is taking a very long time for the pool to re-establish a connection. Like in the order of 10 minutes.

Here is a snippet for how I am using pg-promise:

  const pgp = pgPromise({
    error(err, e) {
      if (e.query) {
        // Do stuff
      }
    },
  });

...

  const pgpArgs = {
    host,
    port,
    database,
    user,
    password,
    max,
    idleTimeoutMillis: 5000,
  };

  const db = pgp(pgpArgs);

I saw this potential answer from the author, but I don't want to kill my entire process just to re-establish the pool.

Is there a way to force clients in pool to re-connect, other than restarting the nodejs process?

Thanks in advance.

rynop
  • 50,086
  • 26
  • 101
  • 112
  • This kind of issue tends to have too many variables involved - server version + configuration, hosting environment, and the OS. Plus your `max` parameter is unknown to us. Maybe connection option `keepAlive` will help you ;) See [here](https://github.com/vitaly-t/pg-promise/wiki/Connection-Syntax). – vitaly-t Mar 04 '21 at 04:38
  • Thanks and thanks for your hard work on `pg-promise`. I could convey those vars, but guessing it wont help much and I don't want to take too much of your time. The big question I have is: does the nodejs process have to be killed and re-started for the pg-pool to re-establish broken connections? You are insinuating "no" with disabling `keepAlive` but I just want to make sure. – rynop Mar 04 '21 at 17:36
  • I suggested that you try to set `keepAlive: true`, I did not insinuate anything else :) – vitaly-t Mar 04 '21 at 20:17
  • :) thanks. I'm struggling to find clear documentation on the implications of setting `keepAlive: true`. node-postgres [seems](https://github.com/brianc/node-postgres/blob/ebe412cf243be35d21ead496d736755217933266/packages/pg/lib/connection-parameters.js#L117) to be using libpq. Libpq [docs](https://www.postgresql.org/docs/12/libpq-connect.html#LIBPQ-KEEPALIVES), nor node-postgres docs are clear on what happens when the connection to server is considered dead. Will it auto re-connect? Or does it require nodejs process restart. I've clarified my Q in my OP. – rynop Mar 04 '21 at 20:55

0 Answers0