donatello
donatello

Reputation: 6275

How to disable connection pooling with PostgreSQL in flask-sqlalchemy?

I want to use pgpool or pgbouncer as an external connection pooler with my flask app. The flask-sqlalchemy extension does not seem to expose a way to change the connection pooler to NullPool. Is there some way to do this?

Upvotes: 2

Views: 2743

Answers (1)

Wolph
Wolph

Reputation: 80111

While it should be possible with the apply_driver_hacks method, I would strongly recommend against it.

The TCP overhead is negligible on a local machine, but the authentication and negotiation (encoding for example) certainly isn't. Keeping a pool is always useful within Flask and if needed can be configured with the SQLALCHEMY_POOL_SIZE, SQLALCHEMY_POOL_TIMEOUT, SQLALCHEMY_POOL_RECYCLE and SQLALCHEMY_MAX_OVERFLOW settings.

If you simply want to cut down on overhead (albeit completely negligible) and your one instance Flask app is the only thing connecting to Postgres, than removing PgBouncer/PgPool from the mix would be better.

Upvotes: 2

Related Questions