简体   繁体   中英

OperationalError could not connect to server: Connection refused

Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?

Trying to deploy my Django app to Heroku and keep getting the following error. I'm not really sure where to start here... I tried killing all processes on port 5432 and restarting Postgres but I'm not too familiar with how to configure the database on Heroku. Thanks for any help.

I'm not quite sure where to start. I've been using the Heroku dev guide and googling the error. Most solutions seem to say to restart Postgres but not working for me.

2020-03-25T05:12:41.000000+00:00 app[api]: Build started by user X@gmail.com
2020-03-25T05:13:20.394227+00:00 heroku[web.1]: Restarting
2020-03-25T05:13:20.397813+00:00 heroku[web.1]: State changed from up to starting
2020-03-25T05:13:20.175463+00:00 app[api]: Deploy a13facac by user X@gmail.com
2020-03-25T05:13:20.175463+00:00 app[api]: Release v18 created by user X@gmail.com
2020-03-25T05:13:21.365822+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-03-25T05:13:21.584742+00:00 heroku[web.1]: Process exited with status 0
2020-03-25T05:13:21.376200+00:00 app[web.1]: [2020-03-25 05:13:21 +0000] [9] [INFO] Worker exiting (pid: 9)
2020-03-25T05:13:21.377965+00:00 app[web.1]: [2020-03-25 05:13:21 +0000] [4] [INFO] Handling signal: term
2020-03-25T05:13:21.377967+00:00 app[web.1]: [2020-03-25 05:13:21 +0000] [10] [INFO] Worker exiting (pid: 10)
2020-03-25T05:13:21.477875+00:00 app[web.1]: [2020-03-25 05:13:21 +0000] [4] [INFO] Shutting down: Master
2020-03-25T05:13:24.895930+00:00 heroku[web.1]: Starting process with command `gunicorn life_cal.wsgi --log-file -`
2020-03-25T05:13:28.209650+00:00 app[web.1]: [2020-03-25 05:13:28 +0000] [4] [INFO] Starting gunicorn 20.0.4
2020-03-25T05:13:28.210642+00:00 app[web.1]: [2020-03-25 05:13:28 +0000] [4] [INFO] Listening at: http://0.0.0.0:19437 (4)
2020-03-25T05:13:28.210794+00:00 app[web.1]: [2020-03-25 05:13:28 +0000] [4] [INFO] Using worker: sync
2020-03-25T05:13:28.216086+00:00 app[web.1]: [2020-03-25 05:13:28 +0000] [9] [INFO] Booting worker with pid: 9
2020-03-25T05:13:28.232500+00:00 app[web.1]: [2020-03-25 05:13:28 +0000] [10] [INFO] Booting worker with pid: 10
2020-03-25T05:13:29.297468+00:00 heroku[web.1]: State changed from starting to up
2020-03-25T05:13:30.000000+00:00 app[api]: Build succeeded
2020-03-25T05:14:56.281785+00:00 heroku[router]: at=info method=GET path="/" host=life-cal.herokuapp.com request_id=a1ca2bf8-9a81-4692-a776-15a9c3e0fd8f fwd="75.7.0.23" dyno=web.1 connect=1ms service=168ms status=500 bytes=228464 protocol=https
2020-03-25T05:14:56.269837+00:00 app[web.1]: Internal Server Error: /
2020-03-25T05:14:56.269861+00:00 app[web.1]: Traceback (most recent call last):
2020-03-25T05:14:56.269862+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
2020-03-25T05:14:56.269863+00:00 app[web.1]: self.connect()
2020-03-25T05:14:56.269863+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
2020-03-25T05:14:56.269864+00:00 app[web.1]: return func(*args, **kwargs)
2020-03-25T05:14:56.269864+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/db/backends/base/base.py", line 197, in connect
2020-03-25T05:14:56.269865+00:00 app[web.1]: self.connection = self.get_new_connection(conn_params)
2020-03-25T05:14:56.269865+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
2020-03-25T05:14:56.269866+00:00 app[web.1]: return func(*args, **kwargs)
2020-03-25T05:14:56.269866+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 185, in get_new_connection
2020-03-25T05:14:56.269866+00:00 app[web.1]: connection = Database.connect(**conn_params)
2020-03-25T05:14:56.269867+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/psycopg2/__init__.py", line 126, in connect
2020-03-25T05:14:56.269867+00:00 app[web.1]: conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
2020-03-25T05:14:56.269868+00:00 app[web.1]: psycopg2.OperationalError: could not connect to server: Connection refused
2020-03-25T05:14:56.269868+00:00 app[web.1]: Is the server running on host "localhost" (127.0.0.1) and accepting
2020-03-25T05:14:56.269868+00:00 app[web.1]: TCP/IP connections on port 5432?
2020-03-25T05:14:56.269869+00:00 app[web.1]: 
2020-03-25T05:14:56.269869+00:00 app[web.1]: 
2020-03-25T05:14:56.269869+00:00 app[web.1]: The above exception was the direct cause of the following exception:
2020-03-25T05:14:56.269870+00:00 app[web.1]: 
2020-03-25T05:14:56.269870+00:00 app[web.1]: Traceback (most recent call last):
2020-03-25T05:14:56.269870+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
2020-03-25T05:14:56.269871+00:00 app[web.1]: response = get_response(request)
2020-03-25T05:14:56.269871+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
2020-03-25T05:14:56.269871+00:00 app[web.1]: response = self.process_exception_by_middleware(e, request)
2020-03-25T05:14:56.269872+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
2020-03-25T05:14:56.269872+00:00 app[web.1]: response = wrapped_callback(request, *callback_args, **callback_kwargs)
2020-03-25T05:14:56.269873+00:00 app[web.1]: File "/app/cal/views.py", line 14, in index
2020-03-25T05:14:56.269873+00:00 app[web.1]: return render(request, 'cal/index.html', context)
2020-03-25T05:14:56.269873+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/shortcuts.py", line 19, in render
2020-03-25T05:14:56.269874+00:00 app[web.1]: content = loader.render_to_string(template_name, context, request, using=using)
2020-03-25T05:14:56.269874+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/loader.py", line 62, in render_to_string
2020-03-25T05:14:56.269875+00:00 app[web.1]: return template.render(context, request)
2020-03-25T05:14:56.269875+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/backends/django.py", line 61, in render
2020-03-25T05:14:56.269875+00:00 app[web.1]: return self.template.render(context)
2020-03-25T05:14:56.269876+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 171, in render
2020-03-25T05:14:56.269876+00:00 app[web.1]: return self._render(context)
2020-03-25T05:14:56.269883+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 163, in _render
2020-03-25T05:14:56.269883+00:00 app[web.1]: return self.nodelist.render(context)
2020-03-25T05:14:56.269884+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 936, in render
2020-03-25T05:14:56.269884+00:00 app[web.1]: bit = node.render_annotated(context)
2020-03-25T05:14:56.269884+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
2020-03-25T05:14:56.269885+00:00 app[web.1]: return self.render(context)
2020-03-25T05:14:56.269885+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/loader_tags.py", line 150, in render
2020-03-25T05:14:56.269885+00:00 app[web.1]: return compiled_parent._render(context)
2020-03-25T05:14:56.269885+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 163, in _render
2020-03-25T05:14:56.269886+00:00 app[web.1]: return self.nodelist.render(context)
2020-03-25T05:14:56.269886+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 936, in render
2020-03-25T05:14:56.269886+00:00 app[web.1]: bit = node.render_annotated(context)
2020-03-25T05:14:56.269887+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
2020-03-25T05:14:56.269887+00:00 app[web.1]: return self.render(context)
2020-03-25T05:14:56.269887+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/loader_tags.py", line 62, in render
2020-03-25T05:14:56.269888+00:00 app[web.1]: result = block.nodelist.render(context)
2020-03-25T05:14:56.269888+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 936, in render
2020-03-25T05:14:56.269888+00:00 app[web.1]: bit = node.render_annotated(context)
2020-03-25T05:14:56.269888+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
2020-03-25T05:14:56.269889+00:00 app[web.1]: return self.render(context)
2020-03-25T05:14:56.269889+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/defaulttags.py", line 166, in render
2020-03-25T05:14:56.269901+00:00 app[web.1]: len_values = len(values)
2020-03-25T05:14:56.269902+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/db/models/query.py", line 258, in __len__
2020-03-25T05:14:56.269902+00:00 app[web.1]: self._fetch_all()
2020-03-25T05:14:56.269902+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/db/models/query.py", line 1261, in _fetch_all
2020-03-25T05:14:56.269903+00:00 app[web.1]: self._result_cache = list(self._iterable_class(self))
2020-03-25T05:14:56.269903+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/db/models/query.py", line 57, in __iter__
2020-03-25T05:14:56.269903+00:00 app[web.1]: results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
2020-03-25T05:14:56.269904+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1149, in execute_sql
2020-03-25T05:14:56.269904+00:00 app[web.1]: cursor = self.connection.cursor()
2020-03-25T05:14:56.269904+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
2020-03-25T05:14:56.269905+00:00 app[web.1]: return func(*args, **kwargs)
2020-03-25T05:14:56.269905+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/db/backends/base/base.py", line 260, in cursor
2020-03-25T05:14:56.269905+00:00 app[web.1]: return self._cursor()
2020-03-25T05:14:56.269905+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/db/backends/base/base.py", line 236, in _cursor
2020-03-25T05:14:56.269906+00:00 app[web.1]: self.ensure_connection()
2020-03-25T05:14:56.269906+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
2020-03-25T05:14:56.269906+00:00 app[web.1]: return func(*args, **kwargs)
2020-03-25T05:14:56.269907+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
2020-03-25T05:14:56.269907+00:00 app[web.1]: self.connect()
2020-03-25T05:14:56.269907+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
2020-03-25T05:14:56.269907+00:00 app[web.1]: raise dj_exc_value.with_traceback(traceback) from exc_value
2020-03-25T05:14:56.269908+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
2020-03-25T05:14:56.269908+00:00 app[web.1]: self.connect()
2020-03-25T05:14:56.269908+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
2020-03-25T05:14:56.269908+00:00 app[web.1]: return func(*args, **kwargs)
2020-03-25T05:14:56.269909+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/db/backends/base/base.py", line 197, in connect
2020-03-25T05:14:56.269909+00:00 app[web.1]: self.connection = self.get_new_connection(conn_params)
2020-03-25T05:14:56.269921+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
2020-03-25T05:14:56.269921+00:00 app[web.1]: return func(*args, **kwargs)
2020-03-25T05:14:56.269922+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 185, in get_new_connection
2020-03-25T05:14:56.269922+00:00 app[web.1]: connection = Database.connect(**conn_params)
2020-03-25T05:14:56.269922+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/psycopg2/__init__.py", line 126, in connect
2020-03-25T05:14:56.269923+00:00 app[web.1]: conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
2020-03-25T05:14:56.269923+00:00 app[web.1]: django.db.utils.OperationalError: could not connect to server: Connection refused
2020-03-25T05:14:56.269924+00:00 app[web.1]: Is the server running on host "localhost" (127.0.0.1) and accepting
2020-03-25T05:14:56.269924+00:00 app[web.1]: TCP/IP connections on port 5432?
2020-03-25T05:14:56.269924+00:00 app[web.1]: 
2020-03-25T05:14:56.270758+00:00 app[web.1]: 10.95.191.28 - - [25/Mar/2020:05:14:56 +0000] "GET / HTTP/1.1" 500 228226 "https://dashboard.heroku.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15"

My settings.py was not being pushed to Heroku because it was listed in my .gitignore. Once I removed that and imported Django_heroku per the Heroku documentation I was able to get everything up and running.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM