我有一个 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/