Я пытаюсь развернуть приложение, написанное на fastapi, в heroku и подключить его к базе данных. Для этого я добавил heroku- postgres (hobbi-dev) в созданный проект, а затем использовал учетные данные базы данных в моем коде веб-приложения.
DATABASE_URL = "postgresql://qpvnasuzcvdwee:d3aecc71083e8f279851285095d9a8cb33f470c5838badaedc5ff1e3ce2df9c5@localhost:5432/detdicolajotpa"
# SQLAlchemy
engine = create_engine(DATABASE_URL)
metadata = MetaData()
# databases query builder
database = Database(DATABASE_URL)
Но в log cosole я получаю
2020-07-14T09:51:16.906646+00:00 heroku[web.1]: Starting process with command `gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app`
2020-07-14T09:51:19.630398+00:00 app[web.1]: [2020-07-14 09:51:19 +0000] [4] [INFO] Starting gunicorn 20.0.4
2020-07-14T09:51:19.631018+00:00 app[web.1]: [2020-07-14 09:51:19 +0000] [4] [INFO] Listening at: http://0.0.0.0:8499 (4)
2020-07-14T09:51:19.631118+00:00 app[web.1]: [2020-07-14 09:51:19 +0000] [4] [INFO] Using worker: uvicorn.workers.UvicornWorker
2020-07-14T09:51:19.636402+00:00 app[web.1]: [2020-07-14 09:51:19 +0000] [10] [INFO] Booting worker with pid: 10
2020-07-14T09:51:19.645490+00:00 app[web.1]: [2020-07-14 09:51:19 +0000] [11] [INFO] Booting worker with pid: 11
2020-07-14T09:51:19.707669+00:00 app[web.1]: [2020-07-14 09:51:19 +0000] [12] [INFO] Booting worker with pid: 12
2020-07-14T09:51:19.759618+00:00 app[web.1]: [2020-07-14 09:51:19 +0000] [15] [INFO] Booting worker with pid: 15
2020-07-14T09:51:20.176702+00:00 heroku[web.1]: State changed from starting to up
2020-07-14T09:51:22.153843+00:00 app[web.1]: [2020-07-14 09:51:22 +0000] [12] [ERROR] Exception in worker process
2020-07-14T09:51:22.153882+00:00 app[web.1]: Traceback (most recent call last):
2020-07-14T09:51:22.153884+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 2339, in _wrap_pool_connect
2020-07-14T09:51:22.153885+00:00 app[web.1]: return fn()
2020-07-14T09:51:22.153886+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/pool/base.py", line 364, in connect
2020-07-14T09:51:22.153887+00:00 app[web.1]: return _ConnectionFairy._checkout(self)
2020-07-14T09:51:22.153887+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/pool/base.py", line 778, in _checkout
2020-07-14T09:51:22.153887+00:00 app[web.1]: fairy = _ConnectionRecord.checkout(pool)
2020-07-14T09:51:22.153888+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/pool/base.py", line 495, in checkout
2020-07-14T09:51:22.153889+00:00 app[web.1]: rec = pool._do_get()
2020-07-14T09:51:22.153889+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/pool/impl.py", line 140, in _do_get
2020-07-14T09:51:22.153890+00:00 app[web.1]: self._dec_overflow()
2020-07-14T09:51:22.153890+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", line 69, in __exit__
2020-07-14T09:51:22.153890+00:00 app[web.1]: exc_value, with_traceback=exc_tb,
2020-07-14T09:51:22.153891+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
2020-07-14T09:51:22.153891+00:00 app[web.1]: raise exception
2020-07-14T09:51:22.153891+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/pool/impl.py", line 137, in _do_get
2020-07-14T09:51:22.153891+00:00 app[web.1]: return self._create_connection()
2020-07-14T09:51:22.153892+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/pool/base.py", line 309, in _create_connection
2020-07-14T09:51:22.153892+00:00 app[web.1]: return _ConnectionRecord(self)
2020-07-14T09:51:22.153892+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/pool/base.py", line 440, in __init__
2020-07-14T09:51:22.153893+00:00 app[web.1]: self.__connect(first_connect_check=True)
2020-07-14T09:51:22.153893+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/pool/base.py", line 661, in __connect
2020-07-14T09:51:22.153895+00:00 app[web.1]: pool.logger.debug("Error on connect(): %s", e)
2020-07-14T09:51:22.153895+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", line 69, in __exit__
2020-07-14T09:51:22.153895+00:00 app[web.1]: exc_value, with_traceback=exc_tb,
2020-07-14T09:51:22.153895+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
2020-07-14T09:51:22.153896+00:00 app[web.1]: raise exception
2020-07-14T09:51:22.153896+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/pool/base.py", line 656, in __connect
2020-07-14T09:51:22.153896+00:00 app[web.1]: connection = pool._invoke_creator(self)
2020-07-14T09:51:22.153897+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
2020-07-14T09:51:22.153897+00:00 app[web.1]: return dialect.connect(*cargs, **cparams)
2020-07-14T09:51:22.153897+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 493, in connect
2020-07-14T09:51:22.153898+00:00 app[web.1]: return self.dbapi.connect(*cargs, **cparams)
2020-07-14T09:51:22.153898+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py", line 127, in connect
2020-07-14T09:51:22.153898+00:00 app[web.1]: conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
2020-07-14T09:51:22.153899+00:00 app[web.1]: psycopg2.OperationalError: could not connect to server: Connection refused
2020-07-14T09:51:22.153899+00:00 app[web.1]: Is the server running on host "localhost" (127.0.0.1) and accepting
2020-07-14T09:51:22.153899+00:00 app[web.1]: TCP/IP connections on port 5432?
Насколько я понял, эта строка psycopg2.OperationalError: could not connect to server: Connection refused
сообщает о проблемах с подключением к базе. Вы можете сказать мне, что я делаю не так? На локальной машине с аналогичными настройками все работает.