A .NET recommendation service uses Npgsql to run vector queries against a single database in Azure Database for PostgreSQL. Three components run in the same application process and create connections directly using new NpgsqlConnection(connectionString). Each component builds its own connection string. The strings are otherwise identical, but each sets a different Maximum Pool Size value.
Monitoring shows far more open server connections than the team expects. You need to make sure that all components share a single connection pool, without adding packages to the solution.
What should you do?
Npgsql enables pooling by default. With connections constructed directly from connection strings in the same process, using identical strings lets the components share a pool. Standardizing the strings removes the separate pools caused by their different maximum-size settings, without requiring another package.
- Not correct: Add the
psycopg_poolpackage to each component. The task forbids new packages, and Npgsql already provides pooling. The cited psycopg_pool package provides pooling for Python psycopg. - Not correct: Double
Maximum Pool Sizein each component's connection string. Doubling the three different values leaves them different, so the components still use separate pools with larger connection limits. - Not correct: Add
Pooling=falseto the connection string in each component. Disabling Npgsql pooling prevents connection reuse through its built-in pools; it does not provide the required shared pool. - Correct: Use one identical connection string in all three components. For this connection-creation pattern within one process, Npgsql associates pools with connection strings. Identical strings let all three components use the same built-in pool.