简体   繁体   English

psycopg2.OperationalError: FATAL: 抱歉,heroku 上已经有太多客户端了

[英]psycopg2.OperationalError: FATAL: sorry, too many clients already on heroku

I tried to push my Flask app to heroku and my app uses Postgres as db.我试图将我的 Flask 应用程序推送到 heroku,我的应用程序使用 Postgres 作为数据库。 However, when I tried to migrate db on heroku using this command但是,当我尝试使用此命令在 heroku 上迁移数据库时

heroku run python manage.py db init --app app

It gives this "too many clients" error for both psycopg2 and sqlalchchemy.它为 psycopg2 和 sqlalchchemy 提供了“客户端太多”错误。

Running python manage.py db migrate on ⬢ petscom... up, run.5707 (Hobby)
Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 2285, in _wrap_pool_connect
    return fn()
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/pool/base.py", line 303, in unique_connection
    return _ConnectionFairy._checkout(self)
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/pool/base.py", line 773, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/pool/base.py", line 492, in checkout
    rec = pool._do_get()
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/pool/impl.py", line 238, in _do_get
    return self._create_connection()
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/pool/base.py", line 308, in _create_connection
    return _ConnectionRecord(self)
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/pool/base.py", line 437, in __init__
    self.__connect(first_connect_check=True)
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/pool/base.py", line 657, in __connect
    pool.logger.debug("Error on connect(): %s", e)
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", line 69, in __exit__
    exc_value, with_traceback=exc_tb,
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/pool/base.py", line 652, in __connect
    connection = pool._invoke_creator(self)
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
    return dialect.connect(*cargs, **cparams)
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 488, in connect
    return self.dbapi.connect(*cargs, **cparams)
  File "/app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py", line 126, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL:  sorry, too many clients already
FATAL:  sorry, too many clients already

After a bit googling, I tried:经过一番谷歌搜索,我尝试了:

  1. heroku pg:killall heroku pg:killall
  2. heroku restart None of those works..... heroku restart 这些都不起作用.....

And I checked heroku pg, it shows 0/20 connections......我检查了heroku pg,它显示了0/20个连接...... 在此处输入图片说明

Some said dont put db connection in loop, but I have to check if some data is in db.有人说不要将db连接放入循环中,但我必须检查db中是否有一些数据。 Here's my code:这是我的代码:

try:
        connection = psycopg2.connect(user="postgres",
                                      password="pass",
                                      host="127.0.0.1",
                                      port="5432",
                                      database="pets")

        cursor = connection.cursor()

        select_all = "select * from pets"
        cursor.execute(select_all)

        # Check if api data in db and save to db
        for index in range(len(myData)):
            # if not exist in db => save to db
            key = myData[index]["animal_id"]
            exists = check_exists(key, cursor)
            if(exists):
                pass
            else:
                doSomething()

I can connect to my local postgres db but not the db on heroku.我可以连接到我的本地 postgres 数据库,但不能连接到 heroku 上的数据库。 How can I deal with this problem?我该如何处理这个问题? Any advise would help :) Thanks!任何建议都会有所帮助:) 谢谢!

I had a similar problem.我有一个类似的问题。 I was able to fix it by setting SQLALCHEMY_TRACK_MODIFICATIONS=False in the environment, destroying the database, and creating a new one.我能够通过在环境中设置SQLALCHEMY_TRACK_MODIFICATIONS=False 、破坏数据库并创建一个新数据库来修复它。

You can destroy it by going to https://data.heroku.com/datastores , opening the database, going to Settings, and selecting 'Destroy Database'.您可以通过访问https://data.heroku.com/datastores来销毁它,打开数据库,转到设置,然后选择“销毁数据库”。

Then provision a new one as you normally would.然后像往常一样配置一个新的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取 OperationalError: FATAL: 抱歉,已经有太多客户在使用 psycopg2 - Getting OperationalError: FATAL: sorry, too many clients already using psycopg2 Django+Postgres FATAL:抱歉,已经有太多客户了 - Django+Postgres FATAL: sorry, too many clients already psycopg2.OperationalError:严重:数据库不存在 - psycopg2.OperationalError: FATAL: database does not exist psycopg2.OperationalError:致命:角色不存在 - psycopg2.OperationalError: FATAL: role does not exist psycopg2.OperationalError:严重:客户端身份验证失败 - psycopg2.OperationalError: FATAL: client authentication failed OperationalError:(psycopg2.OperationalError)严重:用户的密码身份验证失败 - OperationalError: (psycopg2.OperationalError) FATAL: password authentication failed for user psycopg2.OperationalError 错误 - psycopg2.OperationalError errors psycopg2.OperationalError:严重:用户的密码身份验证失败,但该用户不在该计算机上 - psycopg2.OperationalError: FATAL: password authentication failed for user but the user is not on that machine Heroku + Postgres:psycopg2.OperationalError:无法翻译主机名“无” - Heroku + Postgres: psycopg2.OperationalError: could not translate host name “None” 为什么 PostgreSQL 说 FATAL: sorry,当我离最大连接数还很远时,客户端已经太多了? - Why does PostgreSQL say FATAL: sorry, too many clients already when I am nowhere close to the maximum connections?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM