I'd like to better understand Connection Pooling when using Npgsql for Postgres. (http://www.npgsql.org/)
When I use the connection string:
UserID=root;Password=myPassword;Host=localhost;Port=5432;Database=myDataBase;Pooling=true;Minimum Pool Size=0;Maximum Pool Size=100;
Where is the "Pooling" going to take place? On my application server or on the database?
When I call connection.Open(), what happens? Is a connection taken from the pool if one exists and if not, a pool is created?
Any other general info around Connection Pooling would be appreciated.
Thanks.
For an environment without an application server, PostgreSQL provides two implementations of DataSource which an application can use directly. One implementation performs connection pooling, while the other simply provides access to database connections through the DataSource interface without any pooling.
Npgsql is an open source ADO.NET Data Provider for PostgreSQL, it allows programs written in C#, Visual Basic, F# to access the PostgreSQL database server. It is implemented in 100% C# code, is free and is open source.
No, you can only have a single statement executing at the same time on a PostgreSQL connections.
PgBouncer is a light-weight connection pool manager for Greenplum and PostgreSQL. PgBouncer maintains a pool for connections for each database and user combination. PgBouncer either creates a new database connection for a client or reuses an existing connection for the same user and database.
Npgsql connection pooling is implemented inside your application process - it has nothing to do with PostgreSQL, which is completely unaware of it.
The mechanism is very simple. When you close a pooled connection, instead of physically closing the connection to PostgreSQL the physical connection is kept around idle in memory (in a "pool"). The next time you open a new connection, if its connection string matches a physical connection already present in the pool, that physical connection is reused instead of opening a new physical connection.
Since opening/closing physical connections is an expensive process, this considerably speeds up your application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With