关于python:django.db.utils.OperationalError:服务器意外关闭了连接 server closed the connection unexpectedly

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

无法解决什么是错误。

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

当我运行下面的任何命令时,我继续获取跟踪

  • python manage.py生成迁移
  • python manage.py运行服务器
  • Unhandled exception in thread started by
    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
    unserver.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
    ecorder.py", line 65, in applied_migrations
    self.ensure_schema()
    File"C:\Python27\lib\site-packages\django\db\migrations
    ecorder.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.

    事先谢谢。


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

    Linux

    1
    sudo /etc/init.d/postgresql restart

    窗户

    1
    2
    sc stop postgresql
    sc start postgresql

    Mac OS X

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

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