How to reduce number of connections using SQLAlchemy + postgreSQL?

前端 未结 1 928
梦如初夏
梦如初夏 2021-02-04 12:47

I\'m developing on heroku using their Postgres add-on with the Dev plan, which has a connection limit of 20. I\'m new to pyt

相关标签:
1条回答
  • 2021-02-04 13:27

    Within SQL Alchemy you should be able to create a connection pool. This pool is what the pool size would be for each Dyno. On the Dev and Basic plan since you could have up to 20, you could set this at 20 if you run 1 dyno, 10 if you run 2, etc. To configure your pool you can setup the engine:

    engine = create_engine('postgresql://me@localhost/mydb',
                       pool_size=20, max_overflow=0)
    

    This sets up your db engine with a pool which you pull from automatically then. You can also configure the pool manually, more details on that can be found on the pooling guide of SQL Alchemy - http://docs.sqlalchemy.org/en/latest/core/pooling.html

    0 讨论(0)
提交回复
热议问题