繁体   English   中英

django.db.utils.OperationalError: 服务器意外关闭了连接

django.db.utils.OperationalError: server closed the connection unexpectedly

提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供   中文繁体   英文版本   中英对照 版本,有任何建议请联系yoyou2525@163.com。

无法解决是什么错误。

django.db.utils.OperationalError: server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.

当我运行以下任何命令时,我一直在获取跟踪

  1. python manage.py makemigrations
  2. python manage.py runserver
Unhandled exception in thread started by <function wrapper at     0x0000000003DAC4A8>
Traceback (most recent call last): File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper fn(*args, **kwargs)
    File "C:\Python27\lib\site packages\django\core\management\commands\runserver.py", line 124, in inner_run
    self.check_migrations()
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 437, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
    File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 20, in __init__
    self.loader = MigrationLoader(self.connection)
    File "C:\Python27\lib\site-packages\django\db\migrations\loader.py", line 52, in __init__
    self.build_graph()
    File "C:\Python27\lib\site-packages\django\db\migrations\loader.py", line 203, in build_graph
    self.applied_migrations = recorder.applied_migrations()
    File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 65, in applied_migrations
    self.ensure_schema()
    File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 52, in ensure_schema
    if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
    File "C:\Python27\lib\site-packages\django\db\backends\base\base.py", line 231, in cursor
    cursor = self.make_debug_cursor(self._cursor())
    File "C:\Python27\lib\site-packages\django\db\backends\base\base.py", line 204, in _cursor
    self.ensure_connection()
    File "C:\Python27\lib\site-packages\django\db\backends\base\base.py", line 199, in ensure_connection
    self.connect()
    File "C:\Python27\lib\site-packages\django\db\utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
    File "C:\Python27\lib\site-packages\django\db\backends\base\base.py", line 199, in ensure_connection
    self.connect()
    File "C:\Python27\lib\site-packages\django\db\backends\base\base.py", line 171, in connect
    self.connection = self.get_new_connection(conn_params)
    File "C:\Python27\lib\site-packages\django\db\backends\postgresql\base.py", line 176, in get_new_connection
    connection = Database.connect(**conn_params)
    File "C:\Python27\lib\site-packages\psycopg2\__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.

提前致谢。

3 个回复

这通常意味着您的 PostgreSQL 服务器没有正常运行。 您可能希望通过以下方式重新启动它

Linux

sudo /etc/init.d/postgresql restart

窗户

sc stop postgresql
sc start postgresql

Mac OS X

如何在 Mac OS X 上启动 PostgreSQL 服务器?

如果重新启动修复了它,请注意之前服务器故障的根本原因仍然需要调查。

我不认为重启数据库服务器应该是这里的第一步。 这仅在迁移中发生吗? 对该数据库和/或数据库服务器的其他查询是否符合预期?

我再次卸载和安装 postgresql 解决了这个问题。

在 Mac 上

卸载:

brew uninstall --force postgres

安装:

brew install postgres

PS:更改 Linux 或 Windows 的命令。

之后,运行 makemigrations 并迁移。

当进程派生和在父进程中建立的连接在子进程中不起作用时发生。

我使用huggingface/tokenizersBERT来获取句子嵌入,然后将它们插入到 Postgres 数据库中。 首先建立数据库连接,然后分词器分叉,导致相同的django.db.utils.OperationalError

通过禁用TOKENIZER_PARALLELISM解决了它。 虽然对于您的问题,升级到更高版本的Django的可能有助于提到这里

暂无
暂无

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

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