Comments (6)
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.
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.
@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.
@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.
@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.
@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)
- Is a pool gracefully closing db connections when node.js exits? HOT 2
- Is there an event triggered when the pool is being drained? HOT 1
- Problems with config.min HOT 2
- High latency after 10 queries HOT 4
- Want to create connection fail over for multiple endpoint in node-pg-pool
- Support async_hooks HOT 1
- Is there a compelling reason to throw an exception when re-releasing a client? HOT 1
- Connection terminated due to connection timeout / Connection terminated HOT 16
- Is there a difference between pool.query() VS connect(), query(), release() HOT 2
- node-postgres already has connection pooling built in... HOT 1
- release should reset state of connection HOT 1
- Emit 'release' event and add 'activeCount' gettable property to pool HOT 1
- Exception thrown in _remove
- ๅญๆฎต็ฑปๅint8 HOT 1
- pool.end() needs to process pending queries HOT 1
- pool.end() resolves before the last pool.query()
- min connections support HOT 5
- pool.on('error') Documentation Inaccurate
- Cloud Functions: Query timeout with max = 1 HOT 5
- Ambiguous connection timeout parameter
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-pg-pool.