django - PostgreSQL:无法连接到服务器:连接被拒绝

标签 django postgresql cmd

我有一个 Django 项目,我想从 SQLite 切换到 PostgreSQL

安装后,无法运行命令psql

这是回溯:

psql: 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?

操作系统:Windows

最佳答案

默认情况下不启用 TCP/IP 连接,因此您可能必须编辑一个名为 postgres.conf 的文件:

  vi /etc/postgresql/9.4/main/postgresql.conf

对于您来说,它可能位于不同的位置。查找一行内容:

  #listen_addresses = ''        # what IP address(es) to listen on;

将其更改为:

  listen_addresses = '*'        # what IP address(es) to listen on;

在此下方是端口设置。对我来说,它是:

  port = 5432               # (change requires restart)

在同一文件的较高位置有对另一个配置文件的引用:

  hba_file = '/etc/postgresql/9.4/main/pg_hba.conf' # host-based authentication file

继续编辑该文件。您应该插入这样的行:

  host all all 192.168.1.0 255.255.255.0 trust

您的 IP 可能不同。 (一旦确保其正常工作,您可以将“trust”更改为“md5”以获得更好的安全性。)完成此操作后,您需要重新启动 postgres 服务器。

  /usr/lib/postgresql/9.4/bin/pg_ctl restart

关于django - PostgreSQL:无法连接到服务器:连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39542145/

相关文章:

python - 使用 Django REST 框架进行序列化/反序列化的不同序列化器

python - Django channel 错误 : TypeError: __call__() missing 1 required positional argument: 'send'

django - 表格无效...为什么?

c# - 仅在 C# 代码中出现 SQL 语法错误

arrays - PostgreSQL:从 3 个相关表中查询并返回数组

batch-file - CMD:文件任务,打开目录并选择文件

python - 如何从值列表创建 Django 查询集

cmd - ffmpeg encode tiff to h265- error 必须指定至少一个输出文件

windows - 在 cmd 上使用 Cygwin 命令进行彩色输出

c# - UseNpgsql 在 .NET Core 的 IServiceCollection 中不可用