Git Product home page Git Product logo

Comments (6)

brianc avatar brianc commented on June 18, 2024 1

Yeah I think that strategy is good! You might want to add user and password to the uniqueness of a given pool...but I'm not 100% sure about that. It seems like if I wanted to connect to the same database w/ different users I'd expect their connections to be different, but maybe pg-promise takes care of that.

I'm going to leave this issue open so I can be reminded to add the client instance as the 2nd parameter to the error callback. While it is on the error parameter as a property, I agree with you its nicer to be its own thing.

from node-pg-pool.

brianc avatar brianc commented on June 18, 2024

Yah that makes total sense & was likely an oversight on my part.

Just to make sure I'm clear: what you're saying is you want this:

const Pool = require('pg').Pool
const pool = new Pool()
pool.on('error', (error, client) => {
  // client should be the client that threw the error
  // but it's currently null
})

right?

If that's what you're proposing that should be an easy fix!

from node-pg-pool.

vitaly-t avatar vitaly-t commented on June 18, 2024

@brianc Further investigation just showed me that when we get that connection-related error, err is an error object that also happens to have property client set to the right Client object.

That kind of takes care of it, in a sense that I can use it that way, not that it is the best way to do it, because:

  • throwing it into a console or log creates a much larger output, with the Client rendered as extra
  • still inconsistent with how the event is fired in the older way that still works

right?

Yep ๐Ÿ˜„

from node-pg-pool.

vitaly-t avatar vitaly-t commented on June 18, 2024

@brianc While you are here, may I ask a related question?

As within pg-promise the new pool is used automatically, do you think the following strategy is the best one?

For each new triplet of host + port + database I automatically create a new Pool object, and that's how the new pools are being used.

from node-pg-pool.

vitaly-t avatar vitaly-t commented on June 18, 2024

@brianc Thanks, Brian! I do not use user name + password, on the assumption that a separate connection pool on such a granular level would become too fragmented in terms of resources, and thus uncontrollable, i.e. it is better to tweak the size of the pool on the database level, and leave it at that, as far as the generic solutions go. You still get a good connectivity boost and isolation when using different servers / databases.

To make it better, you would have to manually control the pool creation strategy, which In my case isn't suitable, as the connectivity in pg-promise is fully automatic.

P.S. Please make sure that if you move the Client into a parameter, it requires a new release of node-postgres, so I can upgrade the library accordingly, with the code, without it ending up broken silently because the error object no longer has property client.

from node-pg-pool.

sibedge avatar sibedge commented on June 18, 2024

@brianc it seems we have the same issue within the core driver, when creating a Client directly, as per this question: brianc/node-postgres#1351

from node-pg-pool.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.