如何运行远程客户端连接
postgresql
数据库
前提条件是
2
个:
1
,
pg_hba.conf
里面配置了运行远程客户机连接
pg_hba.conf
配置后需要重新加载
reload
生效。
2
,
默认监听只监听本机,需要让监听程序来监听外边连接的端口。
做法:
1
,配置
pg_hba.conf
配置文件在
/opt/postgres/9.0/data
目录,备份后,进行
vi
编辑:
#IPv4localconnections:
host
all
all
127.0.0.1
/
32
password
host
all
all
192.168.1.0/
24
password
host
all
all
192.168.10.0/
24
password
#
加入这行表示运行
192
这个网段的机
器访问所有的数据库。
然后
reload
配置
,指定数据库的数据的目录,其实就是
pg_hba.conf
的目录
[root@fia~]#/opt/postgres/
9.0/bin/pg_ctl
reload-D/opt/postgres/9.0/data
pg_ctl:cannotberunasroot
用户权限不对,
root
也不行
Pleaselogin(using,e.g.,"su")asthe(unprivileged)userthatwill
owntheserverprocess.
[root@fia~]#id
uid=0(root)gid=0(root)groups=0(root)
[root@fia~]#su-postgres
必须用
postgres
用户才能运行
-bash-3.2$/opt/postgres/
9.0/bin/pg_ctl
reload-D/opt/postgres/9.0/data
serversignaled
2
,监听程序
PostgreSQL
默认只监听本地端口,用
netstat-tuln
只会看到“
tcp127.0.0.1:5432LISTEN
”
。
修改
postgresql.conf
中的
listen_address=*
,
监听所有端口,
这样远程才能通过
TCP/IP
登录数
据库,
用
netstat-tuln
会看到“
tcp0.0.0.0:5432LISTEN
”
[root@fia/]#netstat-tuln|grep5432
tcp
0
00.0.0.0:5432
0.0.0.0:*
LISTEN
tcp
0
0:::5432
:::*
LISTEN