我一直在处理这个问题。我设置了一台全新的机器。我已经安装了postgresql和我所有其他依赖项的新副本。基本上,我随机地将这些数据库断开连接。我可以执行相同的请求,无论是有效还是无效。外观非常不确定。在Postgresql上查看日志,它甚至没有连接。现在,我希望如果它从未连接,我会在建立连接和获取光标时遇到此问题,但是我在以后尝试实际使用连接时会得到它。鉴于下面的回溯,我希望看到在pg日志中建立连接,然后由于某种原因断开连接。我没有,所以我想知道是否存在一些不匹配的线索。
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/Django-1.1-py2.6.egg/django/core/handlers/wsgi.py", line 242, in __call__
response = self.get_response(request)
File "/usr/local/lib/python2.6/dist-packages/Django-1.1-py2.6.egg/django/core/handlers/base.py", line 73, in get_response
response = middleware_method(request)
File "/usr/local/lib/python2.6/dist-packages/Django-1.1-py2.6.egg/django/middleware/locale.py", line 16, in process_request
language = translation.get_language_from_request(request)
File "/usr/local/lib/python2.6/dist-packages/Django-1.1-py2.6.egg/django/utils/translation/__init__.py", line 97, in get_language_from_request
return real_get_language_from_request(request)
File "/usr/local/lib/python2.6/dist-packages/Django-1.1-py2.6.egg/django/utils/translation/trans_real.py", line 349, in get_language_from_request
lang_code = request.session.get('django_language', None)
File "/usr/local/lib/python2.6/dist-packages/Django-1.1-py2.6.egg/django/contrib/sessions/backends/base.py", line 63, in get
return self._session.get(key, default)
File "/usr/local/lib/python2.6/dist-packages/Django-1.1-py2.6.egg/django/contrib/sessions/backends/base.py", line 172, in _get_session
self._session_cache = self.load()
File "/usr/local/lib/python2.6/dist-packages/Django-1.1-py2.6.egg/django/contrib/sessions/backends/db.py", line 16, in load
expire_date__gt=datetime.datetime.now()
File "/usr/local/lib/python2.6/dist-packages/Django-1.1-py2.6.egg/django/db/models/manager.py", line 120, in get
return self.get_query_set().get(*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/Django-1.1-py2.6.egg/django/db/models/query.py", line 300, in get
num = len(clone)
File "/usr/local/lib/python2.6/dist-packages/Django-1.1-py2.6.egg/django/db/models/query.py", line 81, in __len__
self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.6/dist-packages/Django-1.1-py2.6.egg/django/db/models/query.py", line 238, in iterator
for row in self.query.results_iter():
File "/usr/local/lib/python2.6/dist-packages/Django-1.1-py2.6.egg/django/db/models/sql/query.py", line 287, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python2.6/dist-packages/Django-1.1-py2.6.egg/django/db/models/sql/query.py", line 2369, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python2.6/dist-packages/Django-1.1-py2.6.egg/django/db/backends/util.py", line 19, in execute
return self.cursor.execute(sql, params)
OperationalError: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
答案 0 :(得分:5)
这是与此处发布的问题非常类似的问题:
Django + FastCGI - randomly raising OperationalError
我想,如果有人最终弄明白,那么答案将是相同的。同样的问题一直困扰着我一个月左右,我不知道是什么原因造成的。
答案 1 :(得分:2)
您是否fork()
子进程(使用preforked FastCGI或类似的东西)?这可能是父进程中建立的连接在子进程中不起作用的原因。如果你使用preforked方法,很容易切换到线程,看看问题是否已经消失。在这种情况下,我看到完全相同的浮动错误。
答案 2 :(得分:2)
答案 3 :(得分:0)
就我而言,我的WSGI服务器uWSGI正在派生我的应用程序进程,以便共享基础连接池。这导致了不确定的行为,(不确定地)正在像OP那样向下发送连接。
我建议确保热切地处理您的应用程序流程。在uWSGI中,您可以使用选项
lazy-apps = true