Npgsql.FSharp icon indicating copy to clipboard operation
Npgsql.FSharp copied to clipboard

question: is it bad idea to keep connection open?

Open eastwing27 opened this issue 2 years ago • 2 comments

ATM our DB has restricted mount of connections (20) but is going to be used intense by many users. |> Sql.connect seems to create new connection each time it;s used so we're risking to reach the limit at the moment we release the feature. Alternatively, we can open a connection by let connection = new NpgsqlConnection(getConnectionString) and keep it open, but is it a good idea? What will happen if users use the same connection?

eastwing27 avatar Mar 12 '22 09:03 eastwing27

No need to worry. Npgsql uses connection pools under the hood. It's enabled by default. https://www.npgsql.org/doc/connection-string-parameters.html#pooling

aaronmu avatar Mar 13 '22 07:03 aaronmu

No need to worry. Npgsql uses connection pools under the hood. It's enabled by default. https://www.npgsql.org/doc/connection-string-parameters.html#pooling

So, if there's a restriction on DB end we should set maximum pool size, is that correct?

eastwing27 avatar Mar 13 '22 07:03 eastwing27