解决postgresql远程连接报错

下载使用第三方软件Navicat for PostgreSQL管理postgresql。
连接时navicat报错:
could not connect to server:Connection refused (0x0000274D/10061)

解决方法:

1.关闭postgresql服务

[postgres@server2 data]$./pg_ctl -D /opt/pgsql/data -l logfile stop

2.修改配置文件/opt/pgsql/data/postgresql.conf

listen_addresses = ‘*’ # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to ‘localhost’; use ‘*’ for all

注:不加引号pg无法启动

[postgres@server2 bin]$ ./postgres -D /opt/pgsql/data
LOG: syntax error in file “/opt/pgsql/data/postgresql.conf” line 60, near token “*”
FATAL: configuration file “/opt/pgsql/data/postgresql.conf” contains errors

3.修改pg_hba.conf
在该配置文件的ipv4配置后面的host all all 127.0.0.1/32 md5行下添加以下配置,或者直接将这一行修改为以下配置

host all all 0.0.0.0/0 trust

4.重启服务

[postgres@server2 data]$./pg_ctl -D /opt/pgsql/data -l logfile start

或者

[postgres@server2 data]$./postgres -D /opt/pgsql/data

你可能感兴趣的:(postgresql)