【问题标题】:Django 1.5 : OperationalError in windows when running "python manage.py syncdb" using postgresql-psycopg2Django 1.5:使用 postgresql-psycopg2 运行“python manage.py syncdb”时 Windows 中的 OperationalError
【发布时间】:2013-05-22 00:29:52
【问题描述】:

这是我的 Django 项目中的 settings.py 文件。操作系统:Windows,主机:本地主机

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'postgres',                     
        'USER': 'JESS',
        'PASSWORD': 'dreamhost',
        'HOST': 'localhost',                     
        'PORT': '5432',                     
    }
}

我按照这个博客的说明安装了 PostgreSQL 和 psycopg2

http://shivul.wordpress.com/2010/05/07/installing-django-with-postgresql-on-windows-and-ubuntu/

在运行python manage.py syncdb 时出现以下错误:

OperationalError: Could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432

Could not connect to server: Connection refused (0x0000274D/10061)
    Is the server running on host "localhost" (127.0.0.1)  and accepting
    TCP/IP connections on port 5432

我什至尝试通过 PostgreSQL 安装文件中的 pgadmin3 应用程序编辑设置,它甚至抛出相同的错误

Could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432

Could not connect to server: Connection refused (0x0000274D/10061)
    Is the server running on host "localhost" (127.0.0.1)  and accepting
    TCP/IP connections on port 5432

我在 stackoverflow 和 internet 中查看了类似的问题,一切都已过时或无法正常工作。

【问题讨论】:

  • 在数据库设置中,为什么你的端口设置为8000?将其更改为5432
  • @karthik : 谢谢..我仍然面临另一个问题 OperationalError : FATAL : password authetication failed for user "JESS"

标签: python django postgresql django-models postgresql-9.2


【解决方案1】:

您的服务器仅侦听 IPv4,但 localhost 正在解析您主机上的 IPv4 和 IPv6 地址。

使用127.0.0.1 而不是localhost 来强制建立IPv4 连接,或者编辑postgresql.conf 来告诉您的PostgreSQL 也监听IPv6。显示postgresql.conf 的listen_addresses 行以获取相关建议,以及select version() 的输出。

【讨论】:

  • 谢谢克雷格,我已经更改了 localhost 值,并且我的 listen_address 有 '*' #for all ,但我现在面临一个新错误:(OperationalError) FATAL: Ident authentication failed for user “username”
  • 我已经查看了您关于类似问题的其他答案“将 pg_hba.conf 编辑为 md5..”我试过了..它仍然抛出相同的错误
  • @jess.intutive 然后您编辑了错误的pg_hba.conf 行,或者您在编辑后忘记重新启动 PostgreSQL。
  • 谢谢克雷格:我已经编辑了 pg_hba.conf 文件并且它正在工作,但是我已经将所有设置的访问权限从“md5”更改为“信任”,在我启动我的网站后会不会有问题应用程序?
  • @jess.intutive 嗯,这是一个可怕的想法,除非你将其限制为来自本地主机的连接,并且你绝对信任本地的一切机器,包括您将以任何用户身份运行的所有其他脚本和代码。我强烈建议使用md5 并设置合适的密码。请阅读 PostgreSQL 文档的客户端认证章节。
【解决方案2】:

我最近遇到了完全相同的消息,但我的问题的原因/解决方案不同。我不确定是什么搞砸了我,但我想是当我看到在 manage.py 中运行 clearsessions 函数时会发生什么。

最后我需要重新启动 postgresql 服务。

为此(Windows 7),

  1. 启动任务管理器 (CTRL+ALT+DEL)
  2. 转到服务选项卡
  3. 点击右下角的服务按钮。

(也可以在开始菜单中搜索“查看本地服务”)

在服务窗口中: 4.找到postgresql-XXXX。 5.点击它,如果它停止,则启动它。

如果它已经在运行,您不妨从那里重新启动它,看看它是否有帮助。我的问题是服务没有在启动时重新启动。

【讨论】:

    猜你喜欢
    • 2013-02-17
    • 1970-01-01
    • 2010-11-25
    • 1970-01-01
    • 2013-06-06
    • 2015-04-25
    • 2016-01-05
    • 1970-01-01
    相关资源
    最近更新 更多