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

Is there an example of pooling connections using pq ? #21

Closed
brailateo opened this issue May 25, 2012 · 4 comments
Closed

Is there an example of pooling connections using pq ? #21

brailateo opened this issue May 25, 2012 · 4 comments

Comments

@brailateo
Copy link

I want to use pq in a middleware program that will serve more than 100 web clients simultaneously and it's possible to need a pool of 10 or 20 active connections to a PostgreSQL database and pool the connections between goroutines serving different web rest-services.
Is there an example how to do that using your pq driver?
In the golang docs there is something written about "database/sql" package:
"If the underlying database driver has the concept of a connection and per-connection session state, the sql package manages creating and freeing connections automatically, including maintaining a free pool of idle connections. "

Best regards,
Constantin Teodorescu

@bmizerany
Copy link
Contributor

database/sql keeps an idle pool. If there is no connection when a request is made, it creates a new one. If the pool is full when the connection is free, it throws it away.

On May 25, 2012, at 12:38 PM, Constantin Teodorescureply@reply.github.com wrote:

I want to use pq in a middleware program that will serve more than 100 web clients simultaneously and it's possible to need a pool of 10 or 20 active connections to a PostgreSQL database and pool the connections between goroutines serving different web rest-services.
Is there an example how to do that using your pq driver?
In the golang docs there is something written about "database/sql" package:
"If the underlying database driver has the concept of a connection and per-connection session state, the sql package manages creating and freeing connections automatically, including maintaining a free pool of idle connections. "

Best regards,
Constantin Teodorescu


Reply to this email directly or view it on GitHub:
https://github.com/bmizerany/pq/issues/21

@brailateo
Copy link
Author

It sounds great but ... are there any fine tunings for pool size like "minimum of opened connections", "maximum of opened connections", "timeout for closing an unused connection" ? I searched for more detail but the golang package doc isn't too clear regarding that.
Thank you a lot for your quick answer,
Teo

@bmizerany
Copy link
Contributor

It's currently hard coded at two. I haven't needed to tune it myself.

If you have more questions regarding database/sql, I recommend asking then on the gonuts mailing list where it's authors can help you more. Pq specific questions can be made here.

On May 25, 2012, at 1:02 PM, Constantin Teodorescureply@reply.github.com wrote:

It sounds great but ... are there any fine tunings for pool size like "minimum of opened connections", "maximum of opened connections", "timeout for closing an unused connection" ? I searched for more detail but the golang package doc isn't too clear regarding that.
Thank you a lot for your quick answer,
Teo


Reply to this email directly or view it on GitHub:
https://github.com/bmizerany/pq/issues/21#issuecomment-5939083

@brailateo
Copy link
Author

OK, I'll ask there and dig a little into the database/sql code to find out!
Thank you again for your time,
Best regards,
Teo
P.S. I'll close the issue!

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

No branches or pull requests

2 participants