我有一个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
答案 0 :(得分:1)
默认情况下未启用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可能有所不同。 (一旦确定这是有效的,您可以更改"信任"到" md5"以获得更好的安全性。)执行此操作后,您需要重新启动postgres服务器。
/usr/lib/postgresql/9.4/bin/pg_ctl restart