PostgreSQL连接出错,could not connect to server:Connection refused(0x0000274D/10061)...

使用navicat连接本地PostgreSQL数据库时报错:

could not connect to server: Connection refused (0x0000274D/10061)  Is the server running on host"localhost" (:1) and acceptingTCP/IP connections on port 5433 ?

could not connect to server: Connection refused (0x0000274D/10061)Is the server running on host"localhost" (127.0.0.1) and acceptingTCP/IP connections on port 5433?

PostgreSQL连接出错,could not connect to server:Connection refused(0x0000274D/10061)...

首先检查一下是不是没有启动PostgreSQL服务,因为没启动服务可能会报这个错误(我就是);

方法如下:

win+R打开输入命令框,输入services.msc打开服务列表。

PostgreSQL连接出错,could not connect to server:Connection refused(0x0000274D/10061)...

右键启动

PostgreSQL连接出错,could not connect to server:Connection refused(0x0000274D/10061)...

再次尝试连接数据库,看是否成功,如果没成功那就进行以下步骤:              

 1、在postgresql的安装文件夹\9.5\data\pg_hba.conf里面找到“# IPv4 local connections:”

PostgreSQL连接出错,could not connect to server:Connection refused(0x0000274D/10061)...          

 然后在这行上面添加“local pgsql all trust”,             
 在它下面的“host    all         all         127.0.0.1/32          md5”             

 下面添加一行,内容为“host all all 192.168.91.1/24 md5”   

PostgreSQL连接出错,could not connect to server:Connection refused(0x0000274D/10061)...

  注:127.0.0.1/32和192.168.91.1/24中的32与24,用32表示该IP被固定,用24表示前3位固定,    
  后面一位可以由自己设,这样,前3位ip地址与该设定相同的计算机就可以访问postgresql数据库。                 

2、PostgreSQL\9.5\data\postgresql.conf文件中,找到“#listen_addresses = 'localhost'”,把它改成“listen_addresses = '*'”。这样,postgresql就可以监听所有ip地址的连接。   

     PostgreSQL连接出错,could not connect to server:Connection refused(0x0000274D/10061)...    PostgreSQL连接出错,could not connect to server:Connection refused(0x0000274D/10061)...

3、然后重启postgresql服务。如果系统启用了防火墙,请先关闭。如果要使用pgadmin连接远程的数据库服务器,须在SSL的选项中选择允许。