2

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?

2
  • Why would you want to disable the flask-sqlalchemy connection pooling? Even with pgpool or pgbouncer (I'd opt for pgbouncer if you don't need pgpool) it is still a good idea to have local connection pooling as well. Just configure pgbouncer to pool based on transactions and it won't matter anyhow :) Commented Sep 10, 2014 at 15:11
  • In my case pgbouncer runs on the same machine as my flask app. So it seems inefficient to do connection pooling twice - once in the flask app and again in pgbouncer. I expect that creating a local TCP connection to pgbouncer is fast. For example - github.com/kljensen/… - suggests that NullPool can be used, but I am not sure exactly how. Commented Sep 10, 2014 at 19:08

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.