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?
-
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 :)Wolph– Wolph2014-09-10 15:11:19 +00:00Commented 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.donatello– donatello2014-09-10 19:08:48 +00:00Commented Sep 10, 2014 at 19:08
1 Answer
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.