推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
larkifly
V2EX  ›  Python

求使用 flask-sqlalchemy 的正确姿势,最近总报 Too many connections 错误, SQLALCHEMY_POOL_SIZE=5

  •  
  •   larkifly · Apr 22, 2016 · 7051 views
    This topic created in 3811 days ago, the information mentioned may be changed or developed.
    如题,已经设置了 SQLALCHEMY_POOL_SIZE=5 ,依然无法解决。

    mysql> show global status like '%connect%';
    +--------------------------+-------+
    | Variable_name | Value |
    +--------------------------+-------+
    | Aborted_connects | 8 |
    | Connections | 374 |
    | Max_used_connections | 21 |
    | Ssl_client_connects | 0 |
    | Ssl_connect_renegotiates | 0 |
    | Ssl_finished_connects | 0 |
    | Threads_connected | 5 |
    +--------------------------+-------+
    6 replies  •  2016-04-26 09:55:47 +08:00
    myyou
        1
    myyou  
       Apr 22, 2016
    你用 db.session.close()了没?
    liyj144
        2
    liyj144  
       Apr 22, 2016
    show variables like "%max_connections%"; 查看最大连接数,我怀疑是 mysql 配置的最大连接数太小, 然后 show processlist; 看看连接情况。
    larkifly
        3
    larkifly  
    OP
       Apr 24, 2016
    @myyou 没有,如果每次都 db.session.close(),那是不是要每次使用的时候,都得 db = SQLAlchemy(app)初始化一下连接???
    myyou
        4
    myyou  
       Apr 25, 2016
    @larkifly 不需要,你只是关闭连接回话( session ),和 SQLAlchemy(app)初始没关系。
    larkifly
        5
    larkifly  
    OP
       Apr 25, 2016
    @myyou 哦,明白了,那么调用 Table.query.filter_by 这样的 select 语句时,需要关闭吗?
    myyou
        6
    myyou  
       Apr 26, 2016
    @larkifly 不需要
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5020 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 63ms · UTC 08:44 · PVG 16:44 · LAX 01:44 · JFK 04:44
    ♥ Do have faith in what you're doing.