Every database offers a limited number of connections because each of them eats resources. If you are using your database in a commercial environment, you configure your database with a maximum number of connections. If you don't do that, the DB will configure some default maximum, it won't offer an unlimited number. So each client application should be written so that it handles a refusal to provide a connection gracefully, and it should close every connection as soon as it has finished with it, otherwise you can run out of connections without good reason. Good practice is to write your application to always close connections as soon as it's finished with them. In the case of Go, the defer mechanism can be used to make this more reliable. However, the app can still hold onto connections, maybe due to programming mistakes. A connection pool enforces a maximum number of connections that a single app can hold, so it stops your app from asking for more than its share. It also watches for idle connections and closes them for you. It's good practice to use a connection pool to iron out the problems that your app fails to handle itself.
Hope this helps. Simon On Friday, June 17, 2016 at 3:32:25 PM UTC+1, Danilo Cicerone wrote: > > Hi to all, > I'm new here and using golang too. I've read some articles and post on > Connection Pooling" but I'm still confused. What I'm looking for is a rule > of thumb that make me easy to decide when use connection pool. My scenario > isn't so complicated: > > - a web application that makes CRUD operations on a Postgres database. > - Minimun 10 clients connected up to 30. > > Moreover, I'm going to use pgx driver. I'd be grateful if you could help > me to get the difference from use or not the connection pool, which is the > best practice? > > Thanks in advance, > > Danilo > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.