Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precision about connexion release #286

Closed
abenhamdine opened this issue Feb 24, 2017 · 2 comments
Closed

Precision about connexion release #286

abenhamdine opened this issue Feb 24, 2017 · 2 comments
Labels

Comments

@abenhamdine
Copy link

abenhamdine commented Feb 24, 2017

Hi Vitaly,

Sorry it this is more suited for a SO question, but I didn't found this point in the documentation, so perhaps it's also a docs enhancement request 😉 .

We are currently using pg module (not pgp), and we used to struggle with connexion leaks, because in some pieces of code, some forgot to call client.release() 😠
As you can imagine, it's very penalizing because with pg (at least with pg < 6.0), AFAIK pg.connect sends no error when the pool is exhausted (see brianc/node-postgres#1006 (comment)).
So the server is simply blocked and hangs indefinitly.

I'm currently evaluating if we should switch to pgpromise, but, because it's build on top of pg, I wonder if the problem is also present

So with pgpromise :

  • should we have to releave every connexion ? or are they released automatically after every query ?
  • what happens if the pool is exhausted ? Is an error sent back ? Or the query is queued until a connexion is available ? Is it possible to set a timeout for that ?

Or in other words : what are the differences with pg on this ?

Thx a lot by advance !

@vitaly-t
Copy link
Owner

vitaly-t commented Feb 24, 2017

should we have to release every connection?

No. It is all done automatically. There are some very unique cases when method connect is used, to be released when no longer needed, but again, you would barely ever need it.

or are they released automatically after every query?

They are indeed, released automatically.

And when you need to execute more than one query at a time against the same connection, you use either tasks (method task) or transactions (method tx).

what happens if the pool is exhausted ? Is an error sent back ? Or the query is queued until a connexion is available ? Is it possible to set a timeout for that?

It will be waiting till a connection becomes available, no error is thrown. The whole pg-promise architecture is however built around the idea of efficient connection use, so it would never happen, if you design your database layer correctly.

what are the differences with pg on this?

I think the above answers just about cover it 😉 But beside the connections management, the differences are endless, I wouldn't know where to start :) For one thing, it has 10x more powerful query formatting engine, best support for external SQL files, really powerful query generators for complex cases, like multi-row inserts and multi-row updates. etc... too many to list here, you should just read the docs ;)

Have a look at the Wiki pages, and of course at the pg-promise-demo 😉

@abenhamdine
Copy link
Author

Thx a lot for this detailled answer !
IMHO this should be more highlighted in the docs, it's useful to know for a newcomer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants